<?php
class ControllerCommunityMcp extends Controller{
    private $error;

    public function index(){
        if (!$this->customer->isLogged()) {
            $this->redirect($this->url->link('account/login', '', 'SSL'));
        }

        if($this->customer->getForumUserType()>3 || ($this->customer->getForumUserType()==3 && !isset($this->request->get['fid']))){
            $this->redirect($this->url->link('error/not_found'),'','SSL');
        }

        $this->language->load('community/mcp');
        $this->language->load('community/community_header');
        $this->load->model('community/mcp');
        $this->load->model('community/user');

        $userPermission=$this->model_community_user->getPermission($this->request->get,$this->customer->getForumUserType(),$this->customer->getForumUserRank());

        if(($this->customer->getForumUserType()==3 && !$userPermission['forum_mod_ids']) || ($this->customer->getForumUserType()==3 && $userPermission['forum_mod_ids'] && !in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])))){
            $this->redirect($this->url->link('error/not_found'),'','SSL');
        }

        if($this->customer->getForumUserType()<3){
            $this->data['has_global_privilege']=TRUE;
        }else{
            $this->data['has_global_privilege']=FALSE;
        }

        $this->document->setTitle($this->language->get('heading_title'));
        $this->data['heading_title']=$this->language->get('heading_title');

        $this->data['breadcrumbs']=array();
        $this->data['breadcrumbs'][]=array(
            'href'      =>      $this->url->link('common/home'),
            'text'      =>      $this->language->get('text_home'),
            'separator'=>      FALSE
        );

        $this->data['breadcrumbs'][]=array(
            'href'      =>      $this->url->link('community/community'),
            'text'      =>      $this->language->get('text_community'),
            'separator' =>      $this->language->get('text_separator')
        );

        $this->data['breadcrumbs'][]=array(
            'href'      =>      $this->url->link('community/mcp'),
            'text'      =>      $this->language->get('text_mcp'),
            'separator' =>      $this->language->get('text_separator')
        );

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['headline_link']=$this->url->link('community/mcp' . $furl);
        $this->data['navi_m_link']=$this->url->link('community/mcp','mode=m' . $furl,'SSL');
        $this->data['navi_mq_link']=$this->url->link('community/mcp','mode=mq' . $furl,'SSL');
        $this->data['navi_rm_link']=$this->url->link('community/mcp','mode=rm' . $furl,'SSL');
        $this->data['navi_w_link']=$this->url->link('community/mcp','mode=w' . $furl,'SSL');
        $this->data['navi_ml_link']=$this->url->link('community/mcp','mode=ml' . $furl,'SSL');
        $this->data['navi_b_link']=$this->url->link('community/mcp','mode=b' . $furl,'SSL');
        $this->data['navi_rde_link']=$this->url->link('community/mcp','mode=rde' . $furl,'SSL');

        $this->data['text_separator']=$this->language->get('text_separator');
        $this->data['text_by']=$this->language->get('text_by');
        $this->data['text_mark_all']=$this->language->get('text_mark_all');
        $this->data['text_unmark_all']=$this->language->get('text_unmark_all');
        $this->data['text_delete']=$this->language->get('text_delete');
        $this->data['text_confirm_delete']=$this->language->get('text_confirm_delete');
        $this->data['text_confirm_submit']=$this->language->get('text_confirm_submit');
        $this->data['text_main']=$this->language->get('text_main');
        $this->data['text_moderation_queue']=$this->language->get('text_moderation_queue');
        $this->data['text_reported_messages']=$this->language->get('text_reported_messages');
        $this->data['text_warnings']=$this->language->get('text_warnings');
        $this->data['text_moderator_logs']=$this->language->get('text_moderator_logs');
        $this->data['text_banning']=$this->language->get('text_banning');
        $this->data['text_restore_deleted']=$this->language->get('text_restore_deleted');

        $this->data['buttons']=array();
        $this->data['button_links']=array();
        $this->data['content_type']='';

        $this->data['navi_m_active']='';
        $this->data['navi_mq_active']='';
        $this->data['navi_rm_active']='';
        $this->data['navi_w_active']='';
        $this->data['navi_ml_active']='';
        $this->data['navi_b_active']='';
        $this->data['navi_rde_active']='';
        $this->data['text_action']='';

        if(!isset($this->request->get['mode'])){
            $this->request->get['mode']='m';
        }

        $this->data['mode_type']=$this->request->get['mode'];

        switch($this->request->get['mode']){
            case 'm':
                $this->main($userPermission);
                break;
            case 'mq':
                $this->moderationQueue();
                break;
            case 'rm':
                $this->reportedMessages();
                break;
            case 'w':
                $this->warnings();
                break;
            case 'ml':
                $this->moderatorLogs();
                break;
            case 'b':
                $this->banning();
                break;
            case 'rde':
                $this->restoreDeleted();
                break;
            default:
                $this->redirect($this->url->link('error/not_found'),'','SSL');
        }

        if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/community/mcp.tpl')){
            $this->template=$this->config->get('config_template') . '/template/community/mcp.tpl';
        }else{
            $this->template='default/template/community/mcp.tpl';
        }

        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header',
            'community/community_header'
        );

        $this->response->setOutput($this->render());
    }

    private function main($userPermission){
        $this->data['navi_m_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['buttons']['fp']=$this->language->get('button_front_page');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=m&action=fp' . $furl,'SSL');

        if(isset($this->request->get['fid'])){
            $this->data['buttons']['vf']=$this->language->get('button_view_forum');
            $this->data['button_links'][]=$this->url->link('community/mcp','mode=m&action=vf' . $furl,'SSL');
        }

        if(isset($this->request->get['tid'])){
            $this->data['buttons']['vt']=$this->language->get('button_view_topic');
            $this->data['button_links'][]=$this->url->link('community/mcp','mode=m&action=vt' . '&fid=' . $this->request->get['fid'] . '&tid=' . $this->request->get['tid'],'SSL');
        }

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'fp';

        switch($this->request->get['action']){
            case 'fp':
                if(isset($this->request->post['approve-posts']) && isset($this->request->post['marked_p_id'])){
                    $this->model_community_mcp->approveTopicAndPost($this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=m&action=fp' . $furl,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['disapprove-posts']) && isset($this->request->post['marked_p_id'])){
                    $this->model_community_mcp->disapproveTopicAndPost($this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=m&action=fp' . $furl,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_front_page');
                $this->data['content_type']='m_fp';
                $this->data['text_action']='fp';

                $this->data['text_latest_posts_approval']=$this->language->get('text_latest_posts_approval');
                $this->data['text_total_posts_approval']=sprintf($this->language->get('text_total_posts_approval'),$this->model_community_mcp->getLatestApprovalPostTotal($this->data['has_global_privilege']));
                $this->data['text_no_posts_approval']=$this->language->get('text_no_posts_approval');
                $this->data['text_notify_poster']=$this->language->get('text_notify_poster');
                $this->data['text_confirm_approval']=$this->language->get('text_confirm_approval');
                $this->data['text_confirm_disapproval']=$this->language->get('text_confirm_disapproval');
                $this->data['text_latest_reports']=$this->language->get('text_latest_reports');
                $this->data['text_total_reports']=sprintf($this->language->get('text_total_reports'),$this->model_community_mcp->getReportTotal($this->data['has_global_privilege']));
                $this->data['text_no_reports']=$this->language->get('text_no_reports');
                $this->data['text_latest_pm_reports']=$this->language->get('text_latest_pm_reports');
                $this->data['text_total_pm_reports']=sprintf($this->language->get('text_total_pm_reports'),$this->model_community_mcp->getOpenPmReportTotal());
                $this->data['text_no_pm_reports']=$this->language->get('text_no_pm_reports');
                $this->data['text_reported_by']=$this->language->get('text_reported_by');
                $this->data['text_forum']=$this->language->get('text_forum');
                $this->data['text_topic']=$this->language->get('text_topic');
                $this->data['text_moderate']=$this->language->get('text_moderate');
                $this->data['text_to']=$this->language->get('text_to');
                $this->data['text_latest_logged_actions']=$this->language->get('text_latest_logged_actions');
                $this->data['text_logged_action']=$this->language->get('text_logged_action');
                $this->data['text_logged_username']=$this->language->get('text_logged_username');
                $this->data['text_logged_user_ip']=$this->language->get('text_logged_user_ip');
                $this->data['text_logged_view_topic']=$this->language->get('text_logged_view_topic');
                $this->data['text_logged_view_logs']=$this->language->get('text_logged_view_logs');
                $this->data['text_logged_time']=$this->language->get('text_logged_time');

                //button
                $this->data['button_approve']=$this->language->get('button_approve');
                $this->data['button_disapprove']=$this->language->get('button_disapprove');

                //5 latest posts awaiting approval
                $approvalPostResults=$this->model_community_mcp->getLatestApprovalPosts($this->data['has_global_privilege']);

                $this->data['approval_posts']=array();

                foreach($approvalPostResults as $approvalPostResult){
                    $this->data['approval_posts'][]=array(
                        'post_moderating_link'      =>      $this->url->link('community/mcp','mode=mq&action=ad' . '&fid=' . $approvalPostResult['forum_id'] . '&pid=' . $approvalPostResult['post_id'],'SSL'),
                        'post_subject'              =>      $approvalPostResult['post_subject'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $approvalPostResult['user_id'] ,'SSL'),$approvalPostResult['username'],date($this->language->get('date_time_format_long'),$approvalPostResult['post_time'])),
                        'topic_link'                =>      $this->url->link('community/viewtopic','fid=' . $approvalPostResult['forum_id'] . '&tid=' . $approvalPostResult['topic_id'],'SSL'),
                        'topic_title'               =>      $approvalPostResult['topic_title'],
                        'topic_moderating_link'     =>      $this->url->link('community/mcp','mode=m&action=vt' . '&tid=' . $approvalPostResult['topic_id'],'SSL'),
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $approvalPostResult['forum_id'],'SSL'),
                        'forum_name'                =>      $approvalPostResult['forum_name'],
                        'forum_moderating_link'     =>      $this->url->link('community/mcp','mode=m&action=vf' . '&fid=' . $approvalPostResult['forum_id'],'SSL'),
                        'post_topic_forum_first_id' =>      $approvalPostResult['post_id'] . '|' . $approvalPostResult['topic_id'] . '|' . $approvalPostResult['forum_id'] . '|' . $approvalPostResult['topic_first_post_id']
                    );

                }

                //5 latest reports
                $reportResults=$this->model_community_mcp->getLatestReports($this->data['has_global_privilege']);

                $this->data['reports']=array();

                foreach($reportResults as $reportResult){
                    $this->data['reports'][]=array(
                        'report_moderating_link'    =>      $this->url->link('community/mcp','mode=rm&action=or' . '&pid=' . $reportResult['post_id'],'SSL'),
                        'post_subject'              =>      $reportResult['post_subject'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $reportResult['user_id'] ,'SSL'),$reportResult['username'],date($this->language->get('date_time_format_long'),$reportResult['post_time'])),
                        'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $reportResult['reporter_id'] ,'SSL'),$reportResult['reporter_name'],date($this->language->get('date_time_format_long'),$reportResult['report_time'])),
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $reportResult['forum_id'],'SSL'),
                        'forum_name'                =>      $reportResult['forum_name']
                    );
                }

                //5 latest pm reports
                $pmReportResults=$this->model_community_mcp->getLatestPmReports();

                $this->data['pm_reports']=array();

                foreach($pmReportResults as $pmReportResult){
                    foreach(unserialize($pmReportResult['to_address']) as $user_name=>$user_id){
                        $pmReportResult['receiver_profile_urls'][]=$this->url->link('community/profile','uid=' . $user_id ,'SSL');
                        $pmReportResult['receiver_names'][]=$user_name;
                    }

                    $this->data['pm_reports'][]=array(
                        'pm_report_moderating_link' =>      $this->url->link('community/mcp','mode=rm&action=prd' . '&fid=' . (isset($this->request->get['fid']) ? $this->request->get['fid'] : '') . '&rid=' . $pmReportResult['report_id'],'SSL'),
                        'message_subject'           =>      $pmReportResult['message_subject'],
                        'sent_by'                   =>      sprintf($this->language->get('text_sent_by'),$this->url->link('community/profile','uid=' . $pmReportResult['user_id'] ,'SSL'),$pmReportResult['username'],date($this->language->get('date_time_format_long'),$pmReportResult['message_time'])),
                        'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $pmReportResult['reporter_id'] ,'SSL'),$pmReportResult['reporter_name'],date($this->language->get('date_time_format_long'),$pmReportResult['report_time'])),
                        'receiver_names'            =>      $pmReportResult['receiver_names'],
                        'receiver_profile_urls'     =>      $pmReportResult['receiver_profile_urls']
                    );
                }
                break;
            case 'vf':
                if(isset($this->request->post['submit']) && $this->request->post['moderate-action']!=-1){
                    $this->model_community_mcp->forumModerateAction($this->request->post,$this->request->get);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=m&action=vf&fid=' . $this->request->get['fid'],'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_view_forum');
                $this->data['text_select_forum']=$this->language->get('text_select_forum');
                $this->data['text_no_topics']=$this->language->get('text_no_topics');
                $this->data['text_heading_topic']=$this->language->get('text_heading_topic');
                $this->data['text_heading_last_post']=$this->language->get('text_heading_last_post');
                $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
                $this->data['text_by']=$this->language->get('text_by');
                $this->data['text_mark_all']=$this->language->get('text_mark_all');
                $this->data['text_unmark_all']=$this->language->get('text_unmark_all');
                $this->data['text_select_action']=$this->language->get('text_select_action');
                $this->data['text_move']=$this->language->get('text_move');
                $this->data['text_lock']=$this->language->get('text_lock');
                $this->data['text_unlock']=$this->language->get('text_unlock');
                $this->data['text_set_as_featured']=$this->language->get('text_set_as_featured');
                $this->data['text_change_to_standard']=$this->language->get('text_change_to_standard');
                $this->data['text_change_to_sticky']=$this->language->get('text_change_to_sticky');
                $this->data['text_change_to_announcement']=$this->language->get('text_change_to_announcement');
                $this->data['text_change_to_global']=$this->language->get('text_change_to_global');
                $this->data['text_stick_topic']=$this->language->get('text_stick_topic');
                $this->data['days']=$this->language->get('days');
                $this->data['text_topic_reported']=$this->language->get('text_topic_reported');
                $this->data['text_topic_awaiting_approval']=$this->language->get('text_topic_awaiting_approval');
                $this->data['button_submit']=$this->language->get('button_submit');

                $this->data['content_type']='m_vf';
                $this->data['text_action']='vf';

                $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

                $this->data['reported_topic_link']=$this->url->link('community/mcp','mode=rm&action=or','SSL');
                $this->data['approve_topic_link']=$this->url->link('community/mcp','mode=mq&action=ad','SSL');

                //moderating permission
                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['post_members_delete']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['post_members_delete'])){
                    $this->data['can_delete_topic']=TRUE;
                }else{
                    $this->data['can_delete_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_move']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_move'])){
                    $this->data['can_move_topic']=TRUE;
                }else{
                    $this->data['can_move_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_lock']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_lock'])){
                    $this->data['can_lock_topic']=TRUE;
                }else{
                    $this->data['can_lock_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_featured']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_featured'])){
                    $this->data['can_feature_topic']=TRUE;
                }else{
                    $this->data['can_feature_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_sticky']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_sticky'])){
                    $this->data['can_stick_topic']=TRUE;
                }else{
                    $this->data['can_stick_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_announcement']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_announcement'])){
                    $this->data['can_announce_topic']=TRUE;
                }else{
                    $this->data['can_announce_topic']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['topic_global_announcement']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['topic_global_announcement'])){
                    $this->data['can_globally_announce_topic']=TRUE;
                }else{
                    $this->data['can_globally_announce_topic']=FALSE;
                }

                $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
                $this->data['forums']=array();
                $this->data['sub_forums']=array();

                foreach($results as $result){
                    $this->data['forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }

                if(isset($this->request->get['fid'])){
                    $this->data['forum_selected']=TRUE;

                    $forumResult=$this->model_community_mcp->getForumInfo($this->request->get);
                    $this->data['forum']['forum_link']=$this->url->link('community/viewforum','fid=' . $forumResult['forum_id'],'SSL');
                    $this->data['forum']['forum_name']=$forumResult['forum_name'];

                    //pagination && topics
                    $pagination = new Pagination();

                    $this->data['topic_total']=$pagination->total=$this->model_community_mcp->getTopicTotal($this->request->get);

                    if (isset($this->request->get['page'])) {
                        $page = $this->request->get['page'];
                    } else {
                        $page = 1;
                    }

                    $pagination->page = $page;
                    $pagination->limit = 20;
                    $start=($page-1)*$pagination->limit;
                    $pagination->url = $this->url->link('community/mcp', 'mode=m&action=vf&fid=' . $this->request->get['fid'] . '&page={page}','SSL');

                    $this->data['pagination'] = $pagination->render();

                    $results=$this->model_community_mcp->getTopics($this->request->get,$start,$pagination->limit);
                    $this->data['topics']=array();

                    foreach($results as $result){
                        $this->data['topics'][]=array(
                            'topic_id'                 =>      $result['topic_id'],
                            'topic_moderate_link'      =>      $this->url->link('community/mcp','mode=m&action=vt' . '&fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),
                            'topic_title'              =>      $result['topic_title'],
                            'is_reported'              =>      $result['topic_reported'],
                            'awaiting_approval'        =>      !$result['topic_approved'],
                            'topic_poster_link'        =>      $this->url->link('community/profile','uid=' . $result['topic_poster_id'] ,'SSL'),
                            'topic_first_poster_name'  =>      $result['topic_first_poster_name'],
                            'topic_time'               =>      date($this->language->get('date_time_format_long'),$result['topic_time']),
                            'topic_last_poster_link'   =>      $this->url->link('community/profile','uid=' . $result['topic_last_poster_id'] ,'SSL'),
                            'topic_last_poster_name'   =>      $result['topic_last_poster_name'],
                            'topic_last_post_time'     =>      date($this->language->get('date_time_format_long'),$result['topic_last_post_time'])
                        );

                        //check topic read/unread status
                        if(time()-$result['topic_last_post_time']>(int)$this->config->get('topics_be_read_time')){
                            switch($result['topic_type']){
                                case '0':
                                    $this->data['topicStatus'][]= $result['topic_status'] ? 'topic_locked_read' : 'topic_read';
                                    break;
                                case '1':
                                    $this->data['topicStatus'][]= $result['topic_status']? 'topic_locked_sticky_read' : 'topic_sticky_read';
                                    break;
                                default:
                                    $this->data['topicStatus'][]= $result['topic_status']? 'announcement_topic_locked_read' : 'announcement_topic_read';
                            }

                            $this->data['text_topic_status'][]=$this->language->get('text_topic_read');
                        }else{
                            if(isset($result['mark_time'])){
                                switch($result['topic_type']){
                                    case '0':
                                        if($result['topic_status']){
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'topic_locked_read' : 'topic_locked_unread';
                                        }else{
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'topic_read' : 'topic_unread';
                                        }
                                        break;
                                    case '1':
                                        if($result['topic_status']){
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'topic_locked_sticky_read' : 'topic_locked_sticky_unread';
                                        }else{
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'topic_sticky_read' : 'topic_sticky_unread';
                                        }
                                        break;
                                    default:
                                        if($result['topic_status']){
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'announcement_topic_locked_read' : 'announcement_topic_locked_unread';
                                        }else{
                                            $this->data['topicStatus'][]=($result['mark_time']>$result['topic_last_post_time']) ? 'announcement_topic_read' : 'announcement_topic_unread';
                                        }
                                }

                                $this->data['text_topic_status'][]=($result['mark_time']>$result['topic_last_post_time']) ? $this->language->get('text_topic_read') : $this->language->get('text_topic_unread');
                            }else{
                                switch($result['topic_type']){
                                    case '0':
                                        $this->data['topicStatus'][]= $result['topic_status'] ? 'topic_locked_unread' : 'topic_unread';
                                        break;
                                    case '1':
                                        $this->data['topicStatus'][]= $result['topic_status'] ? 'topic_locked_sticky_read' : 'topic_sticky_unread';
                                        break;
                                    default:
                                        $this->data['topicStatus'][]= $result['topic_status'] ? 'announcement_topic_locked_unread' : 'announcement_topic_unread';
                                }
                                $this->data['text_topic_status'][]=$this->language->get('text_topic_unread');
                            }
                        }
                    }
                }else{
                    $this->data['forum_selected']=FALSE;
                }

                //get destination forums
                $results=$this->model_community_mcp->getDestinationForums();
                $this->data['des_forums']=array();
                $this->data['des_sub_forums']=array();

                foreach($results as $result){
                    $this->data['des_forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getDestinationSubForums($result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['des_sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }
                break;
            case 'vt':
                if(isset($this->request->post['submit']) && $this->request->post['moderate-action']!=-1 && isset($this->request->post['marked_p_id'])){
                    $moderateResult=$this->model_community_mcp->topicModerateAction($this->request->post,$this->request->get);

                    if($moderateResult){
                        $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=m&action=vf&fid=' . $this->request->get['forum_id'],'SSL');
                    }else{
                        $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=m&action=vt&fid=' . $this->request->get['fid'] . '&tid=' . $this->request->get['tid'],'SSL');
                    }

                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_view_topic');
                $this->data['content_type']='m_vt';
                $this->data['text_action']='vt';

                $this->data['text_select_action']=$this->language->get('text_select_action');
                $this->data['text_lock_post']=$this->language->get('text_lock_post');
                $this->data['text_unlock_post']=$this->language->get('text_unlock_post');
                $this->data['button_submit']=$this->language->get('button_submit');
                $this->data['text_view_report']=$this->language->get('text_view_report');

                //moderating permission
                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['post_members_delete']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['post_members_delete'])){
                    $this->data['can_delete_post']=TRUE;
                }else{
                    $this->data['can_delete_post']=FALSE;
                }

                if($userPermission['role_id']==1 || ($userPermission['role_id']==2 && $userPermission['edit_lock']) || ($userPermission['role_id']==3 && $userPermission['forum_mod_ids'] && in_array($this->customer->getForumUserId(),unserialize($userPermission['forum_mod_ids'])) && $userPermission['edit_lock'])){
                    $this->data['can_lock_post']=TRUE;
                }else{
                    $this->data['can_lock_post']=FALSE;
                }

                //pagination && posts
                $pagination = new Pagination();

                $this->data['post_total']=$pagination->total=$this->model_community_mcp->getPostTotal($this->request->get);

                //if not tid provided
                if(!$this->request->get['tid']){
                    $this->redirect($this->url->link('error/not_found'),'','SSL');
                }

                //if not posts found
                if(!$this->data['post_total']){
                    $this->redirect($this->url->link('error/not_found'),'','SSL');
                }

                //get topic info
                $topicResult=$this->model_community_mcp->getTopicInfo($this->request->get);

                $this->data['topic_first_post_id']=$topicResult['topic_first_post_id'];
                $this->data['topic_last_post_id']=$topicResult['topic_last_post_id'];

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;
                $pagination->url = $this->url->link('community/mcp', 'mode=m&action=vt&tid=' . $this->request->get['tid'] . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $results=$this->model_community_mcp->getPosts($this->request->get,$start,$pagination->limit);

                $this->data['topic_title']=$results[0]['post_subject'];
                $this->data['topic_link']=$this->url->link('community/viewtopic','fid=' . $results[0]['forum_id'] . '&tid=' . $results[0]['topic_id'],'SSL');

                $this->data['posts']=array();

                $i=0;

                foreach($results as $result){
                    $post_contents=$this->parseSpacing($result['post_text']);

                    if($result['enable_bbcode']){
                        $post_contents=$this->parseBbcode($post_contents,$result);
                    }

                    if($result['enable_smilies']){
                        $post_contents=$this->parseSmiles($post_contents,$result);
                    }

                    if($result['enable_magic_url']){
                        $post_contents=$this->parseURL($post_contents,$result);
                    }

                    $this->data['posts'][]=array(
                        'is_reported'      =>      $result['post_reported'],
                        'forum_id'         =>      $result['forum_id'],
                        'post_id'          =>      $result['post_id'],
                        'post_link'        =>      $this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $result['post_id'] . '#' . $result['post_id'],'SSL'),
                        'post_subject'     =>      $result['post_subject'],
                        'poster_link'      =>      $this->url->link('community/profile','uid=' . $result['poster_id'] ,'SSL'),
                        'username'         =>      $result['username'],
                        'post_time'        =>      date($this->language->get('date_time_format_long'),$result['post_time']),
                        'post_text'        =>      $post_contents,
                    );

                    $this->data['posts'][$i]['odd_even_post']=($i%2==0) ? 'odd_post' : 'even_post';

                    $this->data['posts'][$i]['view_report_link']=$this->url->link('community/mcp','mode=rm&action=or' . '&pid=' . $result['post_id'],'SSL');

                    $i++;
                }
                break;
        }
    }

    private function moderationQueue(){
        $this->data['navi_mq_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['buttons']['ta']=$this->language->get('button_topics_awaiting_approval');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=mq&action=ta' . $furl,'SSL');

        $this->data['buttons']['pa']=$this->language->get('button_posts_awaiting_approval');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=mq&action=pa' . $furl,'SSL');

        if(isset($this->request->get['pid'])){
            $this->data['buttons']['ad']=$this->language->get('button_approval_detail');
            $this->data['button_links'][]=$this->url->link('community/mcp','mode=mq&action=ad' . $furl,'SSL');
        }

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'ta';

        switch($this->request->get['action']){
            case 'ta':
                if(isset($this->request->post['approve-topics'])){
                    $this->model_community_mcp->approveTopics($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq&action=ta' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['disapprove-topics'])){
                    $this->model_community_mcp->disapproveTopics($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq&action=ta' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_topics_awaiting_approval');
                $this->data['content_type']='mq_ta';
                $this->data['text_action']='ta';

                $this->data['text_topics_awaiting_approval_intro']=$this->language->get('text_topics_awaiting_approval_intro');
                $this->data['text_all_forum']=$this->language->get('text_all_forum');
                $this->data['text_forum']=$this->language->get('text_forum');
                $this->data['text_no_topics_approval']=$this->language->get('text_no_topics_approval');
                $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
                $this->data['text_heading_location']=$this->language->get('text_heading_location');
                $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
                $this->data['text_notify_poster']=$this->language->get('text_notify_poster');
                $this->data['text_confirm_approval']=$this->language->get('text_confirm_approval');
                $this->data['text_confirm_disapproval']=$this->language->get('text_confirm_disapproval');

                $this->data['button_approve']=$this->language->get('button_approve');
                $this->data['button_disapprove']=$this->language->get('button_disapprove');

                $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

                $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
                $this->data['forums']=array();
                $this->data['sub_forums']=array();

                foreach($results as $result){
                    $this->data['forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }

               //pagination && topics awaiting approval
               $pagination = new Pagination();

               $pagination->total=$this->model_community_mcp->getApprovalTopicTotal($this->request->get);

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;

                if(isset($this->request->get['fid'])){
                    $url='mode=mq&action=ta&fid=' . $this->request->get['fid'];
                }else{
                    $url='mode=mq&action=ta';
                }

                $pagination->url = $this->url->link('community/mcp', $url . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $approvalTopicResults=$this->model_community_mcp->getApprovalTopics($this->request->get,$start,$pagination->limit);

                $this->data['approval_topics']=array();

                foreach($approvalTopicResults as $approvalTopicResult){
                    $this->data['approval_topics'][]=array(
                        'topic_moderating_link'     =>      $this->url->link('community/mcp','mode=mq&action=ad' . '&fid=' . $approvalTopicResult['forum_id'] . '&pid=' . $approvalTopicResult['topic_first_post_id'],'SSL'),
                        'topic_title'               =>      $approvalTopicResult['topic_title'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $approvalTopicResult['user_id'] ,'SSL'),$approvalTopicResult['username'],date($this->language->get('date_time_format_long'),$approvalTopicResult['topic_time'])),
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $approvalTopicResult['forum_id'],'SSL'),
                        'forum_name'                =>      $approvalTopicResult['forum_name'],
                        'topic_id'                  =>      $approvalTopicResult['topic_id']
                    );
                }
                break;
            case 'pa':
                if(isset($this->request->post['approve-posts'])){
                    $this->model_community_mcp->approvePosts($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq&action=pa' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['disapprove-posts'])){
                    $this->model_community_mcp->disapprovePosts($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq&action=pa' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_posts_awaiting_approval');
                $this->data['content_type']='mq_pa';
                $this->data['text_action']='pa';

                $this->data['text_posts_awaiting_approval_intro']=$this->language->get('text_posts_awaiting_approval_intro');
                $this->data['text_all_forum']=$this->language->get('text_all_forum');
                $this->data['text_forum']=$this->language->get('text_forum');
                $this->data['text_topic']=$this->language->get('text_topic');
                $this->data['text_no_posts_approval']=$this->language->get('text_no_posts_approval');
                $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
                $this->data['text_heading_location']=$this->language->get('text_heading_location');
                $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
                $this->data['text_notify_poster']=$this->language->get('text_notify_poster');
                $this->data['text_confirm_approval']=$this->language->get('text_confirm_approval');
                $this->data['text_confirm_disapproval']=$this->language->get('text_confirm_disapproval');

                $this->data['button_approve']=$this->language->get('button_approve');
                $this->data['button_disapprove']=$this->language->get('button_disapprove');

                $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

                $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
                $this->data['forums']=array();
                $this->data['sub_forums']=array();

                foreach($results as $result){
                    $this->data['forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }

                //pagination && posts awaiting approval
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getApprovalPostTotal($this->request->get);

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;

                if(isset($this->request->get['fid'])){
                    $url='mode=mq&action=pa&fid=' . $this->request->get['fid'];
                }else{
                    $url='mode=mq&action=pa';
                }

                $pagination->url = $this->url->link('community/mcp', $url . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $approvalPostResults=$this->model_community_mcp->getApprovalPosts($this->request->get,$start,$pagination->limit);

                $this->data['approval_posts']=array();

                foreach($approvalPostResults as $approvalPostResult){
                    $this->data['approval_posts'][]=array(
                        'post_moderating_link'      =>      $this->url->link('community/mcp','mode=mq&action=ad' . '&fid=' . $approvalPostResult['forum_id'] . '&pid=' . $approvalPostResult['post_id'],'SSL'),
                        'post_subject'              =>      $approvalPostResult['post_subject'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $approvalPostResult['user_id'] ,'SSL'),$approvalPostResult['username'],date($this->language->get('date_time_format_long'),$approvalPostResult['post_time'])),
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $approvalPostResult['forum_id'],'SSL'),
                        'forum_name'                =>      $approvalPostResult['forum_name'],
                        'topic_link'                =>      $this->url->link('community/viewtopic','fid=' . $approvalPostResult['forum_id'] . '&tid=' . $approvalPostResult['topic_id'],'SSL'),
                        'topic_title'               =>      $approvalPostResult['topic_title'],
                        'post_topic_id'             =>      $approvalPostResult['post_id'] . '|' . $approvalPostResult['topic_id']
                    );
                }
                break;
            case 'ad':
                if(isset($this->request->post['approve-post'])){
                    $this->model_community_mcp->approveTopicAndPost($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['disapprove-post'])){
                    $this->model_community_mcp->disapproveTopicAndPost($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=mq' . $url,'SSL');
                    $this->session->data['success_type']='moderate';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_post_detail');
                $this->data['content_type']='mq_ad';
                $this->data['text_action']='ad';

                $this->data['text_notify_poster']=$this->language->get('text_notify_poster');
                $this->data['text_confirm_approve_post']=$this->language->get('text_confirm_approve_post');
                $this->data['text_confirm_disapprove_post']=$this->language->get('text_confirm_disapprove_post');

                $this->data['button_approve']=$this->language->get('button_approve');
                $this->data['button_disapprove']=$this->language->get('button_disapprove');

                $approvalDetailResult=$this->model_community_mcp->getApprovalDetailPost($this->request->get);

                //if not posts found
                if(!$approvalDetailResult){
                    $this->redirect($this->url->link('error/not_found'),'','SSL');
                }

                $post_contents=$this->parseSpacing($approvalDetailResult['post_text']);

                if($approvalDetailResult['enable_bbcode']){
                    $post_contents=$this->parseBbcode($post_contents,$approvalDetailResult);
                }

                if($approvalDetailResult['enable_smilies']){
                    $post_contents=$this->parseSmiles($post_contents,$approvalDetailResult);
                }

                if($approvalDetailResult['enable_magic_url']){
                    $post_contents=$this->parseURL($post_contents,$approvalDetailResult);
                }

                $this->data['approval_detail']=array(
                    'post_link'                 =>      $this->url->link('community/viewtopic','fid=' . $approvalDetailResult['forum_id'] . '&tid=' . $approvalDetailResult['topic_id'] . '&pid' . $approvalDetailResult['post_id'] . '#' . $approvalDetailResult['post_id'],'SSL'),
                    'post_subject'              =>      $approvalDetailResult['post_subject'],
                    'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $approvalDetailResult['user_id'] ,'SSL'),$approvalDetailResult['username'],date($this->language->get('date_time_format_long'),$approvalDetailResult['post_time'])),
                    'post_topic_forum_first_id' =>      $approvalDetailResult['post_id'] . '|' . $approvalDetailResult['topic_id'] . '|' . $approvalDetailResult['forum_id'] . '|' . $approvalDetailResult['topic_first_post_id'],
                    'post_text'                 =>      $post_contents
                );
                break;
        }
    }

    private function reportedMessages(){
       $this->data['navi_rm_active']='class="navi_active"';

       if(isset($this->request->get['fid'])){
           $furl='&fid=' . $this->request->get['fid'];
       }else{
           $furl='';
       }

       $this->data['buttons']['opr']=$this->language->get('button_open_pm_report');
       $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=opr' . $furl,'SSL');

       $this->data['buttons']['cpr']=$this->language->get('button_closed_pm_report');
       $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=cpr' . $furl,'SSL');

       if(isset($this->request->get['rid'])){
           $this->data['buttons']['prd']=$this->language->get('button_pm_report_detail');
           $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=prd' . $furl . '&rid=' . $this->request->get['rid'],'SSL');
       }

       $this->data['buttons']['or']=$this->language->get('button_open_report');
       $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=or' . $furl,'SSL');

       $this->data['buttons']['cr']=$this->language->get('button_closed_report');
       $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=cr' . $furl,'SSL');

       if(isset($this->request->get['rid'])){
           $this->data['buttons']['rd']=$this->language->get('button_report_detail');
           $this->data['button_links'][]=$this->url->link('community/mcp','mode=rm&action=rd' . $furl . '&rid=' . $this->request->get['rid'],'SSL');
       }

       $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'opr';

       switch($this->request->get['action']){
           case 'opr':
               if(isset($this->request->post['delete-reports'])){
                   $this->model_community_mcp->deleteReports($this->request->post);

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=opr' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               if(isset($this->request->post['close-reports'])){
                   $this->model_community_mcp->closeReports($this->request->post);

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=opr' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               $this->data['mcp_heading']=$this->language->get('text_open_pm_report');
               $this->data['content_type']='rm_opr';
               $this->data['text_action']='opr';

               $this->data['text_open_pm_report_intro']=$this->language->get('text_open_pm_report_intro');
               $this->data['text_no_pm_reports']=$this->language->get('text_no_pm_reports');
               $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
               $this->data['text_heading_reporter']=$this->language->get('text_heading_reporter');
               $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
               $this->data['text_to']=$this->language->get('text_to');
               $this->data['text_confirm_close']=$this->language->get('text_confirm_close');

               $this->data['button_delete']=$this->language->get('button_delete');
               $this->data['button_close']=$this->language->get('button_close');

               //pagination && open pm reports
               $pagination = new Pagination();

               $pagination->total=$this->model_community_mcp->getOpenPmReportTotal();

               if (isset($this->request->get['page'])) {
                   $page = $this->request->get['page'];
               } else {
                   $page = 1;
               }

               $pagination->page = $page;
               $pagination->limit = 20;
               $start=($page-1)*$pagination->limit;
               $pagination->url = $this->url->link('community/mcp', 'mode=rm&action=opr' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

               $this->data['pagination'] = $pagination->render();

               $openPmReportResults=$this->model_community_mcp->getOpenPmReports($start,$pagination->limit);

               $this->data['open_pm_reports']=array();

               foreach($openPmReportResults as $openPmReportResult){
                   foreach(unserialize($openPmReportResult['to_address']) as $user_name=>$user_id){
                       $openPmReportResult['receiver_profile_urls'][]=$this->url->link('community/profile','uid=' . $user_id ,'SSL');
                       $openPmReportResult['receiver_names'][]=$user_name;
                   }

                   $this->data['open_pm_reports'][]=array(
                       'pm_report_moderating_link' =>      $this->url->link('community/mcp','mode=rm&action=prd' . '&fid=' . (isset($this->request->get['fid']) ? $this->request->get['fid'] : '') . '&rid=' . $openPmReportResult['report_id'],'SSL'),
                       'message_subject'           =>      $openPmReportResult['message_subject'],
                       'sent_by'                   =>      sprintf($this->language->get('text_sent_by'),$this->url->link('community/profile','uid=' . $openPmReportResult['user_id'] ,'SSL'),$openPmReportResult['username'],date($this->language->get('date_time_format_short'),$openPmReportResult['message_time'])),
                       'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $openPmReportResult['reporter_id'] ,'SSL'),$openPmReportResult['reporter_name'],date($this->language->get('date_time_format_short'),$openPmReportResult['report_time'])),
                       'receiver_names'            =>      $openPmReportResult['receiver_names'],
                       'receiver_profile_urls'     =>      $openPmReportResult['receiver_profile_urls'],
                       'id_str'                    =>      $openPmReportResult['report_id'] . '|' .  $openPmReportResult['topic_id'] . '|' . $openPmReportResult['post_id'] . '|' . $openPmReportResult['pm_id'] . '|' . $openPmReportResult['user_notify']  . '|' . $openPmReportResult['reporter_name'] . '|' . $openPmReportResult['reporter_id'] . '|' . $openPmReportResult['user_id']. '|' . $openPmReportResult['username']
                   );
               }
               break;
           case 'cpr':
               if(isset($this->request->post['delete-reports'])){
                   $this->model_community_mcp->deleteReports($this->request->post);

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=cpr' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               $this->data['mcp_heading']=$this->language->get('text_close_pm_report');
               $this->data['content_type']='rm_cpr';
               $this->data['text_action']='cpr';

               $this->data['text_closed_pm_report_intro']=$this->language->get('text_closed_pm_report_intro');
               $this->data['text_no_pm_reports']=$this->language->get('text_no_pm_reports');
               $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
               $this->data['text_heading_reporter']=$this->language->get('text_heading_reporter');
               $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
               $this->data['text_to']=$this->language->get('text_to');

               $this->data['button_delete']=$this->language->get('button_delete');

               //pagination && closed pm reports
               $pagination = new Pagination();

               $pagination->total=$this->model_community_mcp->getClosedPmReportTotal();

               if (isset($this->request->get['page'])) {
                   $page = $this->request->get['page'];
               } else {
                   $page = 1;
               }

               $pagination->page = $page;
               $pagination->limit = 20;
               $start=($page-1)*$pagination->limit;
               $pagination->url = $this->url->link('community/mcp', 'mode=rm&action=cpr' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

               $this->data['pagination'] = $pagination->render();

               $closedPmReportResults=$this->model_community_mcp->getClosedPmReports($start,$pagination->limit);

               $this->data['closed_pm_reports']=array();

               foreach($closedPmReportResults as $closedPmReportResult){
                   foreach(unserialize($closedPmReportResult['to_address']) as $user_name=>$user_id){
                       $closedPmReportResult['receiver_profile_urls'][]=$this->url->link('community/profile','uid=' . $user_id ,'SSL');
                       $closedPmReportResult['receiver_names'][]=$user_name;
                   }

                   $this->data['closed_pm_reports'][]=array(
                       'pm_report_moderating_link' =>      $this->url->link('community/mcp','mode=rm&action=prd' . '&fid=' . (isset($this->request->get['fid']) ? $this->request->get['fid'] : '') . '&rid=' . $closedPmReportResult['report_id'],'SSL'),
                       'message_subject'           =>      $closedPmReportResult['message_subject'],
                       'sent_by'                   =>      sprintf($this->language->get('text_sent_by'),$this->url->link('community/profile','uid=' . $closedPmReportResult['user_id'] ,'SSL'),$closedPmReportResult['username'],date($this->language->get('date_time_format_short'),$closedPmReportResult['message_time'])),
                       'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $closedPmReportResult['reporter_id'] ,'SSL'),$closedPmReportResult['reporter_name'],date($this->language->get('date_time_format_short'),$closedPmReportResult['report_time'])),
                       'receiver_names'            =>      $closedPmReportResult['receiver_names'],
                       'receiver_profile_urls'     =>      $closedPmReportResult['receiver_profile_urls'],
                       'id_str'                    =>      $closedPmReportResult['report_id'] . '|' .  $closedPmReportResult['topic_id'] . '|' . $closedPmReportResult['post_id'] . '|' . $closedPmReportResult['pm_id'] . '|str|' . $closedPmReportResult['reporter_name'] . '|' . $closedPmReportResult['reporter_id'] . '|' . $closedPmReportResult['user_id']. '|' . $closedPmReportResult['username']
                   );
               }
               break;
           case 'prd':
               if(isset($this->request->post['submit']) && ($this->request->post['moderate-reports']=='delete-reports' || $this->request->post['moderate-reports']=='close-reports') && $this->validateBwFromReport()){
                   if($this->request->post['moderate-reports']=='delete-reports'){
                       $this->model_community_mcp->deleteReports($this->request->post);
                   }elseif($this->request->post['moderate-reports']=='close-reports'){
                       $this->model_community_mcp->closeReports($this->request->post);
                   }

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=opr' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               $this->data['mcp_heading']=$this->language->get('text_pm_report_details');
               $this->data['content_type']='rm_prd';
               $this->data['text_action']='prd';

               $this->data['text_report_reason']=$this->language->get('text_report_reason');
               $this->data['text_report_closed']=$this->language->get('text_report_closed');
               $this->data['text_to']=$this->language->get('text_to');
               $this->data['text_other_action']=$this->language->get('text_other_action');
               $this->data['text_ban_user']=$this->language->get('text_ban_user');
               $this->data['text_warn_user']=$this->language->get('text_warn_user');
               $this->data['text_permanent']=$this->language->get('text_permanent');
               $this->data['text_thirty_minutes']=$this->language->get('text_thirty_minutes');
               $this->data['text_one_hour']=$this->language->get('text_one_hour');
               $this->data['text_six_hours']=$this->language->get('text_six_hours');
               $this->data['text_one_day']=$this->language->get('text_one_day');
               $this->data['text_seven_days']=$this->language->get('text_seven_days');
               $this->data['text_two_weeks']=$this->language->get('text_two_weeks');
               $this->data['text_one_month']=$this->language->get('text_one_month');
               $this->data['text_until']=$this->language->get('text_until');

               $this->data['entry_warning_details']=$this->language->get('entry_warning_details');
               $this->data['entry_ban_reason']=$this->language->get('entry_ban_reason');
               $this->data['entry_ban_reason_shown']=$this->language->get('entry_ban_reason_shown');

               $this->data['button_delete']=$this->language->get('button_delete');
               $this->data['button_close']=$this->language->get('button_close');
               $this->data['button_submit']=$this->language->get('button_submit');

               //value stored in $_post
               if(isset($this->request->post['ban-reason'])){
                   $this->data['ban_reason']=$this->request->post['ban-reason'];
               }else{
                   $this->data['ban_reason']='';
               }

               if(isset($this->request->post['ban-reason-shown'])){
                   $this->data['ban_reason_shown']=$this->request->post['ban-reason-shown'];
               }else{
                   $this->data['ban_reason_shown']='';
               }

               if(isset($this->request->post['ban-date'])){
                   $this->data['ban_date']=$this->request->post['ban-date'];
               }else{
                   $this->data['ban_date']='';
               }

               if(isset($this->request->post['warning-details'])){
                   $this->data['warning_details']=$this->request->post['warning-details'];
               }else{
                   $this->data['warning_details']='';
               }

               //error
               if($this->error['report_details']){
                   $this->data['error_report_details']=$this->error['report_details'];
               }else{
                   $this->data['error_report_details']='';
               }

               $pmReportDetailsResult=$this->model_community_mcp->getPmReportDetails($this->request->get);

               //if no pm found
               if(!$pmReportDetailsResult){
                   $this->redirect($this->url->link('error/not_found'),'','SSL');
               }

               $message_text=$this->parseSpacing($pmReportDetailsResult['message_text']);

               $parsing_permission=array(
                   'posting_bbcode'       =>TRUE,
                   'posting_bbcode_img'   =>TRUE,
                   'posting_bbcode_flash' =>TRUE,
                   'posting_bbcode_url'   =>TRUE,
                   'posting_smiles'       =>TRUE
               );

               $message_text=$this->parseBbcode($message_text,$parsing_permission);
               $message_text=$this->parseSmiles($message_text,$parsing_permission);
               $message_text=$this->parseURL($message_text,$parsing_permission);

               foreach(unserialize($pmReportDetailsResult['to_address']) as $user_name=>$user_id){
                   $pmReportDetailsResult['receiver_profile_urls'][]=$this->url->link('community/profile','uid=' . $user_id ,'SSL');
                   $pmReportDetailsResult['receiver_names'][]=$user_name;
               }

               $this->data['pm_report_detail']=array(
                   'reason_title'           =>      $pmReportDetailsResult['reason_title'],
                   'reported_by'            =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $pmReportDetailsResult['reporter_id'] ,'SSL'),$pmReportDetailsResult['reporter_name'],date($this->language->get('date_time_format_short'),$pmReportDetailsResult['report_time'])),
                   'report_closed'          =>      $pmReportDetailsResult['report_closed'],
                   'report_info'            =>      $pmReportDetailsResult['report_info'],
                   'message_subject'        =>      $pmReportDetailsResult['message_subject'],
                   'sent_by'                =>      sprintf($this->language->get('text_sent_by'),$this->url->link('community/profile','uid=' . $pmReportDetailsResult['user_id'] ,'SSL'),$pmReportDetailsResult['username'],date($this->language->get('date_time_format_short'),$pmReportDetailsResult['message_time'])),
                   'message_text'           =>      $message_text,
                   'receiver_names'         =>      $pmReportDetailsResult['receiver_names'],
                   'receiver_profile_urls'  =>      $pmReportDetailsResult['receiver_profile_urls'],
                   'id_str'                 =>      $pmReportDetailsResult['report_id'] . '|' .  $pmReportDetailsResult['topic_id'] . '|' . $pmReportDetailsResult['post_id'] . '|' . $pmReportDetailsResult['pm_id'] . '|' . $pmReportDetailsResult['user_notify']  . '|' . $pmReportDetailsResult['reporter_name'] . '|' . $pmReportDetailsResult['reporter_id'] . '|' . $pmReportDetailsResult['user_id']. '|' . $pmReportDetailsResult['username'] . '|' . $pmReportDetailsResult['user_type']
               );
               break;
           case 'or':
               if(isset($this->request->post['delete-reports'])){
                   $this->model_community_mcp->deleteReports($this->request->post);

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=or' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               if(isset($this->request->post['close-reports'])){
                   $this->model_community_mcp->closeReports($this->request->post);

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=or' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               $this->data['mcp_heading']=$this->language->get('text_open_report');
               $this->data['content_type']='rm_or';
               $this->data['text_action']='or';

               $this->data['text_open_report_intro']=$this->language->get('text_open_report_intro');
               $this->data['text_all_forum']=$this->language->get('text_all_forum');
               $this->data['text_forum']=$this->language->get('text_forum');
               $this->data['text_no_reports']=$this->language->get('text_no_reports');
               $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
               $this->data['text_heading_reporter']=$this->language->get('text_heading_reporter');
               $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
               $this->data['text_confirm_close']=$this->language->get('text_confirm_close');

               $this->data['button_delete']=$this->language->get('button_delete');
               $this->data['button_close']=$this->language->get('button_close');

               $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

               $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
               $this->data['forums']=array();
               $this->data['sub_forums']=array();

               foreach($results as $result){
                   $this->data['forums'][]=array(
                       'forum_id'      =>      $result['forum_id'],
                       'forum_name'    =>      $result['forum_name']
                   );

                   $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                   foreach($subForums as $subForum){
                       $this->data['sub_forums'][$result['forum_id']][]=array(
                           'forum_id'      =>      $subForum['forum_id'],
                           'forum_name'    =>      $subForum['forum_name']
                       );
                   }
               }

               //pagination && open reports
               $pagination = new Pagination();

               $pagination->total=$this->model_community_mcp->getOpenReportTotal($this->request->get);

               if (isset($this->request->get['page'])) {
                   $page = $this->request->get['page'];
               } else {
                   $page = 1;
               }

               $pagination->page = $page;
               $pagination->limit = 20;
               $start=($page-1)*$pagination->limit;
               $pagination->url = $this->url->link('community/mcp', 'mode=rm&action=or' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

               $this->data['pagination'] = $pagination->render();

               $this->data['open_reports']=array();

               $openReportResults=$this->model_community_mcp->getOpenReports($this->request->get,$start,$pagination->limit);

               foreach($openReportResults as $openReportResult){
                   $this->data['open_reports'][]=array(
                       'report_moderating_link'    =>      $this->url->link('community/mcp','mode=rm&action=rd' . '&fid=' . (isset($this->request->get['fid']) ? $this->request->get['fid'] : '') . '&rid=' . $openReportResult['report_id'],'SSL'),
                       'post_subject'              =>      $openReportResult['post_subject'],
                       'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $openReportResult['user_id'] ,'SSL'),$openReportResult['username'],date($this->language->get('date_time_format_long'),$openReportResult['post_time'])),
                       'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $openReportResult['reporter_id'] ,'SSL'),$openReportResult['reporter_name'],date($this->language->get('date_time_format_long'),$openReportResult['report_time'])),
                       'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $openReportResult['forum_id'],'SSL'),
                       'forum_name'                =>      $openReportResult['forum_name'],
                       'id_str'                    =>      $openReportResult['report_id'] . '|' .  $openReportResult['topic_id'] . '|' . $openReportResult['post_id'] . '|' . $openReportResult['pm_id'] . '|' . $openReportResult['user_notify']  . '|' . $openReportResult['reporter_name'] . '|' . $openReportResult['reporter_id'] . '|' . $openReportResult['user_id']. '|' . $openReportResult['username']
                   );
               }
               break;
           case 'cr':
               $this->data['mcp_heading']=$this->language->get('text_closed_report');
               $this->data['content_type']='rm_cr';
               $this->data['text_action']='cr';

               $this->data['text_closed_report_intro']=$this->language->get('text_closed_report_intro');
               $this->data['text_all_forum']=$this->language->get('text_all_forum');
               $this->data['text_forum']=$this->language->get('text_forum');
               $this->data['text_no_reports']=$this->language->get('text_no_reports');
               $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
               $this->data['text_heading_reporter']=$this->language->get('text_heading_reporter');
               $this->data['text_heading_mark']=$this->language->get('text_heading_mark');

               $this->data['button_delete']=$this->language->get('button_delete');

               $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

               $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
               $this->data['forums']=array();
               $this->data['sub_forums']=array();

               foreach($results as $result){
                   $this->data['forums'][]=array(
                       'forum_id'      =>      $result['forum_id'],
                       'forum_name'    =>      $result['forum_name']
                   );

                   $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                   foreach($subForums as $subForum){
                       $this->data['sub_forums'][$result['forum_id']][]=array(
                           'forum_id'      =>      $subForum['forum_id'],
                           'forum_name'    =>      $subForum['forum_name']
                       );
                   }
               }

               //pagination && closed reports
               $pagination = new Pagination();

               $pagination->total=$this->model_community_mcp->getClosedReportTotal($this->request->get);

               if (isset($this->request->get['page'])) {
                   $page = $this->request->get['page'];
               } else {
                   $page = 1;
               }

               $pagination->page = $page;
               $pagination->limit = 20;
               $start=($page-1)*$pagination->limit;
               $pagination->url = $this->url->link('community/mcp', 'mode=rm&action=cr' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

               $this->data['pagination'] = $pagination->render();

               $this->data['closed_reports']=array();

               $closedReportResults=$this->model_community_mcp->getClosedReports($this->request->get,$start,$pagination->limit);

               foreach($closedReportResults as $closedReportResult){
                   $this->data['closed_reports'][]=array(
                       'report_moderating_link'    =>      $this->url->link('community/mcp','mode=rm&action=rd' . '&fid=' . (isset($this->request->get['fid']) ? $this->request->get['fid'] : '') . '&rid=' . $closedReportResult['report_id'],'SSL'),
                       'post_subject'              =>      $closedReportResult['post_subject'],
                       'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $closedReportResult['user_id'] ,'SSL'),$closedReportResult['username'],date($this->language->get('date_time_format_long'),$closedReportResult['post_time'])),
                       'reported_by'               =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $closedReportResult['reporter_id'] ,'SSL'),$closedReportResult['reporter_name'],date($this->language->get('date_time_format_long'),$closedReportResult['report_time'])),
                       'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $closedReportResult['forum_id'],'SSL'),
                       'forum_name'                =>      $closedReportResult['forum_name'],
                       'id_str'                    =>      $closedReportResult['report_id'] . '|' .  $closedReportResult['topic_id'] . '|' . $closedReportResult['post_id'] . '|' . $closedReportResult['pm_id']
                   );
               }
               break;
           case 'rd':
               if(isset($this->request->post['submit']) && ($this->request->post['moderate-reports']=='delete-reports' || $this->request->post['moderate-reports']=='close-reports') && $this->validateBwFromReport()){

                   if($this->request->post['moderate-reports']=='delete-reports'){
                       $this->model_community_mcp->deleteReports($this->request->post);
                   }elseif($this->request->post['moderate-reports']=='close-reports'){
                       $this->model_community_mcp->closeReports($this->request->post);
                   }

                   if(isset($this->request->get['fid'])){
                       $url='&fid=' . $this->request->get['fid'];
                   }else{
                       $url='';
                   }

                   $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rm&action=or' . $url,'SSL');
                   $this->session->data['success_type']='moderate_report';
                   $this->redirect($this->url->link('community/success','','SSL'));
               }

               $this->data['mcp_heading']=$this->language->get('text_report_details');
               $this->data['content_type']='rm_rd';
               $this->data['text_action']='rd';

               $this->data['text_report_reason']=$this->language->get('text_report_reason');
               $this->data['text_report_closed']=$this->language->get('text_report_closed');
               $this->data['text_delete_post']=$this->language->get('text_delete_post');
               $this->data['text_post_deleted']=$this->language->get('text_post_deleted');
               $this->data['text_other_action']=$this->language->get('text_other_action');
               $this->data['text_ban_user']=$this->language->get('text_ban_user');
               $this->data['text_warn_user']=$this->language->get('text_warn_user');
               $this->data['text_permanent']=$this->language->get('text_permanent');
               $this->data['text_thirty_minutes']=$this->language->get('text_thirty_minutes');
               $this->data['text_one_hour']=$this->language->get('text_one_hour');
               $this->data['text_six_hours']=$this->language->get('text_six_hours');
               $this->data['text_one_day']=$this->language->get('text_one_day');
               $this->data['text_seven_days']=$this->language->get('text_seven_days');
               $this->data['text_two_weeks']=$this->language->get('text_two_weeks');
               $this->data['text_one_month']=$this->language->get('text_one_month');
               $this->data['text_until']=$this->language->get('text_until');

               $this->data['entry_warning_details']=$this->language->get('entry_warning_details');
               $this->data['entry_ban_reason']=$this->language->get('entry_ban_reason');
               $this->data['entry_ban_reason_shown']=$this->language->get('entry_ban_reason_shown');

               $this->data['button_delete']=$this->language->get('button_delete');
               $this->data['button_close']=$this->language->get('button_close');
               $this->data['button_submit']=$this->language->get('button_submit');

               //value stored in $_post
               if(isset($this->request->post['ban-reason'])){
                   $this->data['ban_reason']=$this->request->post['ban-reason'];
               }else{
                   $this->data['ban_reason']='';
               }

               if(isset($this->request->post['ban-reason-shown'])){
                   $this->data['ban_reason_shown']=$this->request->post['ban-reason-shown'];
               }else{
                   $this->data['ban_reason_shown']='';
               }

               if(isset($this->request->post['ban-date'])){
                   $this->data['ban_date']=$this->request->post['ban-date'];
               }else{
                   $this->data['ban_date']='';
               }

               if(isset($this->request->post['warning-details'])){
                   $this->data['warning_details']=$this->request->post['warning-details'];
               }else{
                   $this->data['warning_details']='';
               }

               //error
               if($this->error['report_details']){
                   $this->data['error_report_details']=$this->error['report_details'];
               }else{
                   $this->data['error_report_details']='';
               }

               $reportDetailsResult=$this->model_community_mcp->getReportDetails($this->request->get);

               //if no report found
               if(!$reportDetailsResult){
                   $this->redirect($this->url->link('error/not_found'),'','SSL');
               }

               $post_contents=$this->parseSpacing($reportDetailsResult['post_text']);

               if($reportDetailsResult['enable_bbcode']){
                   $post_contents=$this->parseBbcode($post_contents,$reportDetailsResult);
               }

               if($reportDetailsResult['enable_smilies']){
                   $post_contents=$this->parseSmiles($post_contents,$reportDetailsResult);
               }

               if($reportDetailsResult['enable_magic_url']){
                   $post_contents=$this->parseURL($post_contents,$reportDetailsResult);
               }

               $this->data['report_detail']=array(
                   'reason_title'           =>      $reportDetailsResult['reason_title'],
                   'reported_by'            =>      sprintf($this->language->get('text_reported_by'),$this->url->link('community/profile','uid=' . $reportDetailsResult['reporter_id'] ,'SSL'),$reportDetailsResult['reporter_name'],date($this->language->get('date_time_format_short'),$reportDetailsResult['report_time'])),
                   'report_closed'          =>      $reportDetailsResult['report_closed'],
                   'report_info'            =>      $reportDetailsResult['report_info'],
                   'post_subject'           =>      $reportDetailsResult['post_subject'],
                   'post_link'              =>      $this->url->link('community/viewtopic','fid=' . $reportDetailsResult['forum_id'] . '&tid=' . $reportDetailsResult['topic_id'] . '&pid=' . $reportDetailsResult['post_id'] . '#' . $reportDetailsResult['post_id'],'SSL'),
                   'posted_by'              =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $reportDetailsResult['user_id'] ,'SSL'),$reportDetailsResult['username'],date($this->language->get('date_time_format_long'),$reportDetailsResult['post_time'])),
                   'post_text'              =>      $post_contents,
                   'post_deleted'           =>      $reportDetailsResult['post_deleted'],
                   'id_str'                 =>      $reportDetailsResult['report_id'] . '|' .  $reportDetailsResult['topic_id'] . '|' . $reportDetailsResult['post_id'] . '|' . $reportDetailsResult['pm_id'] . '|' . $reportDetailsResult['user_notify']  . '|' . $reportDetailsResult['reporter_name'] . '|' . $reportDetailsResult['reporter_id'] . '|' . $reportDetailsResult['user_id']. '|' . $reportDetailsResult['username'] . '|' . $reportDetailsResult['user_type']
               );
               break;
       }
    }

    public function warnings(){
        $this->data['navi_w_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['buttons']['iw']=$this->language->get('button_issue_warning');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=w&action=iw' . $furl,'SSL');

        $this->data['buttons']['wl']=$this->language->get('button_warning_list');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=w&action=wl' . $furl,'SSL');

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'iw';

        switch($this->request->get['action']){
            case 'iw':
                if(isset($this->request->post['submit']) && $this->validateWarning()){
                    $this->model_community_mcp->addWarning($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=w&action=iw' . $url,'SSL');
                    $this->session->data['success_type']='warning';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_issue_warning');
                $this->data['content_type']='w_iw';
                $this->data['text_action']='iw';

                $this->data['text_issue_warning_intro']=sprintf($this->language->get('text_issue_warning_intro'),$this->config->get('warning_ban_time_span')/(60*60*24),$this->config->get('warning_ban_count'));

                $this->data['entry_select_username']=$this->language->get('entry_select_username');
                $this->data['entry_warning_details']=$this->language->get('entry_warning_details');

                $this->data['button_submit']=$this->language->get('button_submit');

                if(isset($this->request->post['warning-usernames'])){
                    $this->data['warning_usernames']=$this->request->post['warning-usernames'];
                }else{
                    $this->data['warning_usernames']='';
                }

                if(isset($this->request->post['warning-details'])){
                    $this->data['warning_details']=$this->request->post['warning-details'];
                }else{
                    $this->data['warning_details']='';
                }

                if($this->error['warning']){
                    $this->data['error_warning']=$this->error['warning'];
                }else{
                    $this->data['error_warning']='';
                }
                break;
            case 'wl':
                $this->data['mcp_heading']=$this->language->get('text_warning_list');
                $this->data['content_type']='w_wl';
                $this->data['text_action']='wl';

                $this->data['text_warning_list_intro']=sprintf($this->language->get('text_warning_list_intro'),$this->config->get('warning_ban_time_span')/(60*60*24),$this->config->get('warning_ban_count'));
                $this->data['text_no_warnings']=$this->language->get('text_no_warnings');
                $this->data['text_heading_username']=$this->language->get('text_heading_username');
                $this->data['text_heading_latest_warning']=$this->language->get('text_heading_latest_warning');
                $this->data['text_heading_warning_count']=$this->language->get('text_heading_warning_count');

                //pagination
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getWarnedUserTotal();

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;
                $pagination->url = $this->url->link('community/mcp', 'mode=w&action=wl' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $results=$this->model_community_mcp->getWarnedUsers($start,$pagination->limit);

                $this->data['warnigs']=array();

                foreach($results as $result){
                    $this->data['warnigs'][]=array(
                        'user_profile_link'  =>      $this->url->link('community/profile','uid=' . $result['user_id'] ,'SSL'),
                        'username'           =>      $result['username'],
                        'user_warnings'      =>      $result['user_warnings'],
                        'user_last_warning'  =>      date($this->language->get('date_time_format_long'),$result['user_last_warning'])
                    );
                }
                break;
        }
    }

    public function moderatorLogs(){
        $this->data['navi_ml_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $this->data['furl']='&fid=' . $this->request->get['fid'];
        }else{
            $this->data['furl']='';
        }

        $this->data['buttons']['fl']=$this->language->get('button_forum_logs');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=ml&action=fl' . $this->data['furl'],'SSL');

        if(isset($this->request->get['tid'])){
            $this->data['buttons']['tl']=$this->language->get('button_topic_logs');
            $this->data['button_links'][]=$this->url->link('community/mcp','mode=ml&action=tl' . $this->data['furl'],'SSL');
        }

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'fl';

        if(isset($this->request->post['delete-all'])){
            $this->model_community_mcp->deleteAllForumLogs($this->request->get);

            $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=ml&action=fl' . $this->data['furl'],'SSL');
            $this->session->data['success_type']='log';
            $this->redirect($this->url->link('community/success','','SSL'));
        }

        if(isset($this->request->post['delete-marked']) && isset($this->request->post['marked_l_id'])){
            $this->model_community_mcp->deleteForumLogs($this->request->get,$this->request->post);

            $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=ml&action=fl' . $this->data['furl'],'SSL');
            $this->session->data['success_type']='log';
            $this->redirect($this->url->link('community/success','','SSL'));
        }

        if(isset($this->request->get['kw'])){
            $this->data['keyword']=$this->request->get['kw'];
        }else{
            $this->data['keyword']='';
        }

        $this->data['mcp_heading']=$this->language->get('text_forum_logs');
        $this->data['content_type']='ml_fl';
        $this->data['text_action']='fl';

        $this->data['text_no_logs']=$this->language->get('text_no_logs');
        $this->data['text_heading_operator']=$this->language->get('text_heading_operator');
        $this->data['text_heading_ip']=$this->language->get('text_heading_ip');
        $this->data['text_heading_time']=$this->language->get('text_heading_time');
        $this->data['text_heading_action']=$this->language->get('text_heading_action');
        $this->data['text_heading_mark']=$this->language->get('text_heading_mark');
        $this->data['text_select_forum']=$this->language->get('text_select_forum');

        $this->data['button_search']=$this->language->get('button_search');
        $this->data['button_delete_all']=$this->language->get('button_delete_all');
        $this->data['button_delete_marked']=$this->language->get('button_delete_marked');

        $this->data['entry_search_keywords']=$this->language->get('entry_search_keywords');

        $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

        $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
        $this->data['forums']=array();
        $this->data['sub_forums']=array();

        foreach($results as $result){
            $this->data['forums'][]=array(
                'forum_id'      =>      $result['forum_id'],
                'forum_name'    =>      $result['forum_name']
            );

            $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

            foreach($subForums as $subForum){
                $this->data['sub_forums'][$result['forum_id']][]=array(
                    'forum_id'      =>      $subForum['forum_id'],
                    'forum_name'    =>      $subForum['forum_name']
                );
            }
        }

        //pagination
        $pagination = new Pagination();

        if(isset($this->request->get['kw'])){
            $pagination->total=$this->model_community_mcp->getForumLogSearchResultTotal($this->request->get);
        }else{
            $pagination->total=$this->model_community_mcp->getForumLogTotal($this->request->get);
        }

        if (isset($this->request->get['page'])) {
            $page = $this->request->get['page'];
        } else {
            $page = 1;
        }

        $pagination->page = $page;
        $pagination->limit = 20;
        $start=($page-1)*$pagination->limit;
        $pagination->url = $this->url->link('community/mcp', 'mode=ml&action=fl' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

        $this->data['pagination'] = $pagination->render();

        if(isset($this->request->get['kw'])){
            $results=$this->model_community_mcp->getForumLogSearchResult($this->request->get,$start,$pagination->limit);
        }else{
            $results=$this->model_community_mcp->getForumLogs($this->request->get,$start,$pagination->limit);
        }

        $this->data['forum_logs']=array();

        $i=0;
        foreach($results as $result){
            $this->data['forum_logs'][]=array(
                'log_id'                =>      $result['log_id'],
                'operator_profile_link' =>      $this->url->link('community/profile','uid=' . $result['operator_id'] ,'SSL'),
                'operator_name'         =>      $result['username'],
                'log_ip'                =>      $result['log_ip'],
                'log_time'              =>      date($this->language->get('date_time_format_short'),$result['log_time'])
            );

            $actionArray=unserialize($result['log_data']);

            switch($result['log_type']){
                case 'topic_delete':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_delete'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_move':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_move'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$actionArray[0],$this->url->link('community/viewtopic','fid=' . $actionArray[4] . '&tid=' . $result['topic_id'],'SSL'),$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3],$this->url->link('community/viewforum','fid=' . $actionArray[4],'SSL'),$actionArray[5]);
                    break;
                case 'topic_lock':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_lock'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_unlock':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_unlock'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_feature':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_feature'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_announce':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_announce'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$actionArray[2],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[4]);
                    break;
                case 'topic_globally_announce':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_globally_announce'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$actionArray[2]);
                    break;
                case 'topic_standard':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_standard'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_stick':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_stick'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$actionArray[2],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[4]);
                    break;
                case 'topic_approve':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_approve'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3],$actionArray[4]=='yes'?'yes':'no');
                    break;
                case 'topic_disapprove':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_disapprove'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3],$actionArray[4]=='yes'?'yes':'no');
                    break;
                case 'topic_solve':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_solve'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'topic_unsolve':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_topic_unsolve'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[0],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[3]);
                    break;
                case 'post_delete':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_delete'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$actionArray[0],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[3],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[4]);
                    break;
                case 'post_edit':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_edit'),$this->url->link('community/profile','uid=' . $actionArray[2],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[0] . '#' . $actionArray[0],'SSL'),$actionArray[1],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[4],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[5]);
                    break;
                case 'post_lock':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_lock'),$this->url->link('community/profile','uid=' . $actionArray[2],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[0] . '#' . $actionArray[0],'SSL'),$actionArray[1],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[4],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[5]);
                    break;
                case 'post_unlock':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_unlock'),$this->url->link('community/profile','uid=' . $actionArray[2],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[0] . '#' . $actionArray[0],'SSL'),$actionArray[1],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[4],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[5]);
                    break;
                case 'post_approve':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_approve'),$this->url->link('community/profile','uid=' . $actionArray[2],'SSL'),$actionArray[3],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[0] . '#' . $actionArray[0],'SSL'),$actionArray[1],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[4],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[5],$actionArray[6]=='yes'?'yes':'no');
                    break;
                case 'post_disapprove':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_post_disapprove'),$this->url->link('community/profile','uid=' . $actionArray[1],'SSL'),$actionArray[2],$actionArray[0],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'],'SSL'),$actionArray[3],$this->url->link('community/viewforum','fid=' . $result['forum_id'],'SSL'),$actionArray[4],$actionArray[5]=='yes'?'yes':'no');
                    break;
                case 'report_close':
                    $str='';
                    if(!empty($actionArray[3])){
                        $str.=sprintf($this->language->get('text_action_report_close_a'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[3] . '#' . $actionArray[3],'SSL'),$actionArray[4],$actionArray[12]=='yes'?'yes':'no');
                    }else{
                        $str.=sprintf($this->language->get('text_action_report_close_b'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2],$actionArray[4],$actionArray[12]=='yes'?'yes':'no');
                    }

                    if(!empty($actionArray[5])){
                        $str.=sprintf($this->language->get('text_action_warn'),$this->url->link('community/profile','uid=' . $actionArray[5],'SSL'),$actionArray[6],$actionArray[7]);
                    }

                    if(!empty($actionArray[8])){
                        $str.=sprintf($this->language->get('text_action_ban'),$this->url->link('community/profile','uid=' . $actionArray[8],'SSL'),$actionArray[9],$actionArray[10],$actionArray[11]);
                    }

                    $this->data['forum_logs'][$i]['log_action']=$str;
                    break;
                case 'report_delete':
                    $str='';
                    if(!empty($actionArray[3])){
                        $str.=sprintf($this->language->get('text_action_report_delete_a'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2],$this->url->link('community/viewtopic','fid=' . $result['forum_id'] . '&tid=' . $result['topic_id'] . '&pid=' . $actionArray[3] . '#' . $actionArray[3],'SSL'),$actionArray[4]);
                    }else{
                        $str.=sprintf($this->language->get('text_action_report_delete_b'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2],$actionArray[4]);
                    }

                    if(!empty($actionArray[5])){
                        $str.=sprintf($this->language->get('text_action_warn'),$this->url->link('community/profile','uid=' . $actionArray[5],'SSL'),$actionArray[6],$actionArray[7]);
                    }

                    if(!empty($actionArray[8])){
                        $str.=sprintf($this->language->get('text_action_ban'),$this->url->link('community/profile','uid=' . $actionArray[8],'SSL'),$actionArray[9],$actionArray[10],$actionArray[11]);
                    }

                    $this->data['forum_logs'][$i]['log_action']=$str;
                    break;
                case 'pm_report_close':
                    $str=sprintf($this->language->get('text_action_pm_report_close'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2],$actionArray[10]);

                    if(!empty($actionArray[3])){
                        $str.=sprintf($this->language->get('text_action_warn'),$this->url->link('community/profile','uid=' . $actionArray[3],'SSL'),$actionArray[4],$actionArray[5]);
                    }

                    if(!empty($actionArray[6])){
                        $str.=sprintf($this->language->get('text_action_ban'),$this->url->link('community/profile','uid=' . $actionArray[6],'SSL'),$actionArray[7],$actionArray[8],$actionArray[9]);
                    }

                    $this->data['forum_logs'][$i]['log_action']=$str;
                    break;
                case 'pm_report_delete':
                    $str=sprintf($this->language->get('text_action_pm_report_delete'),empty($actionArray[0])?$actionArray[1]:$actionArray[0],$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[2]);

                    if(!empty($actionArray[3])){
                        $str.=sprintf($this->language->get('text_action_warn'),$this->url->link('community/profile','uid=' . $actionArray[3],'SSL'),$actionArray[4],$actionArray[5]);
                    }

                    if(!empty($actionArray[6])){
                        $str.=sprintf($this->language->get('text_action_ban'),$this->url->link('community/profile','uid=' . $actionArray[6],'SSL'),$actionArray[7],$actionArray[8],$actionArray[9]);
                    }

                    $this->data['forum_logs'][$i]['log_action']=$str;
                    break;
                case 'user_ban':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_ban_user'),$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[0],date($this->language->get('date_time_format_short'),$actionArray[1]),$actionArray[2],$actionArray[3]);
                    break;
                case 'ip_ban':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_ban_ip'),$actionArray[0],date($this->language->get('date_time_format_short'),$actionArray[1]),$actionArray[2],$actionArray[3]);
                    break;
                case 'user_unban':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_unban_user'),$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[0]);
                    break;
                case 'ip_unban':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_unban_ip'),$actionArray[0]);
                    break;
                case 'user_warn':
                    $this->data['forum_logs'][$i]['log_action']=sprintf($this->language->get('text_action_warn_user'),$this->url->link('community/profile','uid=' . $result['user_id'],'SSL'),$actionArray[0],$actionArray[1]);
                    break;
            }
        $i++;
        }

        if($this->customer->getForumUserType()==1){
            $this->data['show_delete_buttons']=TRUE;
        }else{
            $this->data['show_delete_buttons']=FALSE;
        }
    }

    public function banning(){
        $this->data['navi_b_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['buttons']['bu']=$this->language->get('button_ban_username');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=b&action=bu' . $furl,'SSL');

        $this->data['buttons']['bi']=$this->language->get('button_ban_ip');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=b&action=bi' . $furl,'SSL');

        $this->data['buttons']['ubu']=$this->language->get('button_unban_username');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=b&action=ubu' . $furl,'SSL');

        $this->data['buttons']['ubi']=$this->language->get('button_unban_ip');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=b&action=ubi' . $furl,'SSL');

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'bu';

        switch($this->request->get['action']){
            case 'bu':
                if(isset($this->request->post['submit'])&& $this->validateBanning()){
                    $this->model_community_mcp->BanUsers($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=b&action=bu' . $url,'SSL');
                    $this->session->data['success_type']='banning';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_ban_username');
                $this->data['content_type']='b_bu';
                $this->data['text_action']='bu';

                $this->data['text_ban_username_intro']=$this->language->get('text_ban_username_intro');
                $this->data['text_permanent']=$this->language->get('text_permanent');
                $this->data['text_thirty_minutes']=$this->language->get('text_thirty_minutes');
                $this->data['text_one_hour']=$this->language->get('text_one_hour');
                $this->data['text_six_hours']=$this->language->get('text_six_hours');
                $this->data['text_one_day']=$this->language->get('text_one_day');
                $this->data['text_seven_days']=$this->language->get('text_seven_days');
                $this->data['text_two_weeks']=$this->language->get('text_two_weeks');
                $this->data['text_one_month']=$this->language->get('text_one_month');
                $this->data['text_until']=$this->language->get('text_until');

                $this->data['entry_username']=$this->language->get('entry_username');
                $this->data['entry_ban_length']=$this->language->get('entry_ban_length');
                $this->data['entry_ban_reason']=$this->language->get('entry_ban_reason');
                $this->data['entry_ban_reason_shown']=$this->language->get('entry_ban_reason_shown');

                $this->data['button_submit']=$this->language->get('button_submit');

                //value stored in $_post
                if(isset($this->request->post['ban-usernames'])){
                    $this->data['ban_usernames']=$this->request->post['ban-usernames'];
                }else{
                    $this->data['ban_usernames']='';
                }

                if(isset($this->request->post['ban-reason'])){
                    $this->data['ban_reason']=$this->request->post['ban-reason'];
                }else{
                    $this->data['ban_reason']='';
                }

                if(isset($this->request->post['ban-reason-shown'])){
                    $this->data['ban_reason_shown']=$this->request->post['ban-reason-shown'];
                }else{
                    $this->data['ban_reason_shown']='';
                }

                if(isset($this->request->post['ban-date'])){
                    $this->data['ban_date']=$this->request->post['ban-date'];
                }else{
                    $this->data['ban_date']='';
                }

                //error
                if($this->error['banning']){
                    $this->data['error_banning']=$this->error['banning'];
                }else{
                    $this->data['error_banning']='';
                }
                break;
            case 'bi':
                if(isset($this->request->post['submit'])&& $this->validateBanning()){
                    $this->model_community_mcp->BanIps($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=b&action=bi' . $url,'SSL');
                    $this->session->data['success_type']='banning';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_ban_ip');
                $this->data['content_type']='b_bi';
                $this->data['text_action']='bi';

                $this->data['text_ban_ip_intro']=$this->language->get('text_ban_ip_intro');
                $this->data['text_permanent']=$this->language->get('text_permanent');
                $this->data['text_thirty_minutes']=$this->language->get('text_thirty_minutes');
                $this->data['text_one_hour']=$this->language->get('text_one_hour');
                $this->data['text_six_hours']=$this->language->get('text_six_hours');
                $this->data['text_one_day']=$this->language->get('text_one_day');
                $this->data['text_seven_days']=$this->language->get('text_seven_days');
                $this->data['text_two_weeks']=$this->language->get('text_two_weeks');
                $this->data['text_one_month']=$this->language->get('text_one_month');
                $this->data['text_until']=$this->language->get('text_until');

                $this->data['entry_ip']=$this->language->get('entry_ip');
                $this->data['entry_ban_length']=$this->language->get('entry_ban_length');
                $this->data['entry_ban_reason']=$this->language->get('entry_ban_reason');
                $this->data['entry_ban_reason_shown']=$this->language->get('entry_ban_reason_shown');

                $this->data['button_submit']=$this->language->get('button_submit');

                //value stored in $_post
                if(isset($this->request->post['ban-ips'])){
                    $this->data['ban_ips']=$this->request->post['ban-ips'];
                }else{
                    $this->data['ban_ips']='';
                }

                if(isset($this->request->post['ban-reason'])){
                    $this->data['ban_reason']=$this->request->post['ban-reason'];
                }else{
                    $this->data['ban_reason']='';
                }

                if(isset($this->request->post['ban-reason-shown'])){
                    $this->data['ban_reason_shown']=$this->request->post['ban-reason-shown'];
                }else{
                    $this->data['ban_reason_shown']='';
                }

                if(isset($this->request->post['ban-date'])){
                    $this->data['ban_date']=$this->request->post['ban-date'];
                }else{
                    $this->data['ban_date']='';
                }

                //error
                if($this->error['banning']){
                    $this->data['error_banning']=$this->error['banning'];
                }else{
                    $this->data['error_banning']='';
                }
                break;
            case 'ubu':
                if(isset($this->request->post['submit'])){
                    $this->model_community_mcp->unban($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=b&action=ubu' . $url,'SSL');
                    $this->session->data['success_type']='banning';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_unban_username');
                $this->data['content_type']='b_ubu';
                $this->data['text_action']='ubu';

                $this->data['text_unban_username_intro']=$this->language->get('text_unban_username_intro');
                $this->data['text_no_banned_users']=$this->language->get('text_no_banned_users');
                $this->data['text_ban_length']=$this->language->get('text_ban_length');
                $this->data['text_ban_reason']=$this->language->get('text_ban_reason');
                $this->data['text_ban_reason_shown']=$this->language->get('text_ban_reason_shown');

                $this->data['button_submit']=$this->language->get('button_submit');

                //pagination
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getBannedUserTotal();

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;
                $pagination->url = $this->url->link('community/mcp', 'mode=b&action=ubu' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $results=$this->model_community_mcp->getBannedUsers($start,$pagination->limit);

                $this->data['banned_users']=array();

                foreach($results as $result){
                    $this->data['banned_users'][]=array(
                        'username'           =>      $result['username'],
                        'user_profile_link'  =>      $this->url->link('community/profile','uid=' . $result['user_id'] ,'SSL'),
                        'ban_reason'         =>      $result['ban_reason'],
                        'ban_give_reason'    =>      $result['ban_give_reason'],
                        'ban_end_time'       =>      ($result['ban_end_time']!=0 ? date($this->language->get('date_time_format_long'),$result['ban_end_time']) : $this->language->get('text_permanent')),
                        'ban_id'             =>      $result['ban_id']
                    );
                }
                break;
            case 'ubi':
                if(isset($this->request->post['submit'])){
                    $this->model_community_mcp->unban($this->request->post);

                    if(isset($this->request->get['fid'])){
                        $url='&fid=' . $this->request->get['fid'];
                    }else{
                        $url='';
                    }

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=b&action=ubi' . $url,'SSL');
                    $this->session->data['success_type']='banning';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_unban_ip');
                $this->data['content_type']='b_ubi';
                $this->data['text_action']='ubi';

                $this->data['text_unban_ip_intro']=$this->language->get('text_unban_ip_intro');
                $this->data['text_no_banned_ips']=$this->language->get('text_no_banned_ips');
                $this->data['text_ban_length']=$this->language->get('text_ban_length');
                $this->data['text_ban_reason']=$this->language->get('text_ban_reason');
                $this->data['text_ban_reason_shown']=$this->language->get('text_ban_reason_shown');

                $this->data['button_submit']=$this->language->get('button_submit');

                //pagination
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getBannedIpTotal();

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;
                $pagination->url = $this->url->link('community/mcp', 'mode=b&action=ubi' . (isset($this->request->get['fid']) ? '&fid=' . $this->request->get['fid'] : '') . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $results=$this->model_community_mcp->getBannedIps($start,$pagination->limit);

                $this->data['banned_ips']=array();

                foreach($results as $result){
                    $this->data['banned_ips'][]=array(
                        'ban_ip'             =>      ($result['ban_ip_start']==0 ? long2ip($result['ban_ip_end']) : long2ip($result['ban_ip_start']) . '-' . long2ip($result['ban_ip_end'])),
                        'ban_reason'         =>      $result['ban_reason'],
                        'ban_give_reason'    =>      $result['ban_give_reason'],
                        'ban_end_time'       =>      ($result['ban_end_time']!=0 ? date($this->language->get('date_time_format_long'),$result['ban_end_time']) : $this->language->get('text_permanent')),
                        'ban_id'             =>      $result['ban_id']
                    );
                }
                break;
        }
    }

    private function restoreDeleted(){
        $this->data['navi_rde_active']='class="navi_active"';

        if(isset($this->request->get['fid'])){
            $furl='&fid=' . $this->request->get['fid'];
        }else{
            $furl='';
        }

        $this->data['buttons']['dt']=$this->language->get('button_topics_deleted');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=rde&action=dt' . $furl,'SSL');

        $this->data['buttons']['dp']=$this->language->get('button_posts_deleted');
        $this->data['button_links'][]=$this->url->link('community/mcp','mode=rde&action=dp' . $furl,'SSL');

        $this->request->get['action']=isset($this->request->get['action']) ? $this->request->get['action'] : 'dt';

        switch($this->request->get['action']){
            case 'dt':
                if(isset($this->request->post['restore']) && isset($this->request->post['marked_t_id'])){
                    $this->model_community_mcp->restoreDeletedTopics($this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dt' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['clear-marked']) && isset($this->request->post['marked_t_id'])){
                    $this->model_community_mcp->clearMarkedDeletedTopics($this->request->get,$this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dt' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['clear-all'])){
                    $this->model_community_mcp->clearAllDeletedTopics($this->request->get);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dt' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_topics_deleted');
                $this->data['content_type']='rde_dt';
                $this->data['text_action']='dt';

                $this->data['text_topics_deleted_intro']=$this->language->get('text_topics_deleted_intro');
                $this->data['text_all_forum']=$this->language->get('text_all_forum');
                $this->data['text_forum']=$this->language->get('text_forum');
                $this->data['text_no_topics_deleted']=$this->language->get('text_no_topics_deleted');
                $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
                $this->data['text_heading_location']=$this->language->get('text_heading_location');
                $this->data['text_heading_mark']=$this->language->get('text_heading_mark');

                $this->data['button_restore']=$this->language->get('button_restore');
                $this->data['button_clear_marked']=$this->language->get('button_clear_marked');
                $this->data['button_clear_all']=$this->language->get('button_clear_all');

                $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

                $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
                $this->data['forums']=array();
                $this->data['sub_forums']=array();

                foreach($results as $result){
                    $this->data['forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }

                //pagination && topics awaiting approval
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getDeletedTopicTotal($this->request->get);

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;

                if(isset($this->request->get['fid'])){
                    $url='mode=rde&action=dt&fid=' . $this->request->get['fid'];
                }else{
                    $url='mode=rde&action=dt';
                }

                $pagination->url = $this->url->link('community/mcp', $url . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $deletedTopicResults=$this->model_community_mcp->getDeletedTopics($this->request->get,$start,$pagination->limit);

                $this->data['deleted_topics']=array();

                foreach($deletedTopicResults as $deletedTopicResult){
                    $this->data['deleted_topics'][]=array(
                        'topic_title'               =>      $deletedTopicResult['topic_title'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $deletedTopicResult['topic_first_post_id'] ,'SSL'),$deletedTopicResult['topic_first_poster_name'],date($this->language->get('date_time_format_long'),$deletedTopicResult['topic_time'])),
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $deletedTopicResult['forum_id'],'SSL'),
                        'forum_name'                =>      $deletedTopicResult['forum_name'],
                        'topic_id'                  =>      $deletedTopicResult['topic_id']
                    );
                }
                break;
            case 'dp':
                if(isset($this->request->post['restore']) && isset($this->request->post['marked_p_id'])){
                    $this->model_community_mcp->restoreDeletedPosts($this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dp' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['clear-marked']) && isset($this->request->post['marked_p_id'])){
                    $this->model_community_mcp->clearMarkedDeletedPosts($this->request->get,$this->request->post);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dp' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                if(isset($this->request->post['clear-all'])){
                    $this->model_community_mcp->clearAllDeletedPosts($this->request->get);

                    $this->session->data['forwarded_link']=$this->url->link('community/mcp','mode=rde&action=dp' . $furl,'SSL');
                    $this->session->data['success_type']='update_deleted';
                    $this->redirect($this->url->link('community/success','','SSL'));
                }

                $this->data['mcp_heading']=$this->language->get('text_posts_deleted');
                $this->data['content_type']='rde_dp';
                $this->data['text_action']='dp';

                $this->data['text_posts_deleted_intro']=$this->language->get('text_posts_deleted_intro');
                $this->data['text_all_forum']=$this->language->get('text_all_forum');
                $this->data['text_forum']=$this->language->get('text_forum');
                $this->data['text_topic']=$this->language->get('text_topic');
                $this->data['text_no_posts_deleted']=$this->language->get('text_no_posts_deleted');
                $this->data['text_heading_view_details']=$this->language->get('text_heading_view_details');
                $this->data['text_heading_location']=$this->language->get('text_heading_location');
                $this->data['text_heading_mark']=$this->language->get('text_heading_mark');

                $this->data['button_restore']=$this->language->get('button_restore');
                $this->data['button_clear_marked']=$this->language->get('button_clear_marked');
                $this->data['button_clear_all']=$this->language->get('button_clear_all');

                $this->data['forum_option_id']=isset($this->request->get['fid']) ? $this->request->get['fid'] : '';

                $results=$this->model_community_mcp->getForums($this->data['has_global_privilege']);
                $this->data['forums']=array();
                $this->data['sub_forums']=array();

                foreach($results as $result){
                    $this->data['forums'][]=array(
                        'forum_id'      =>      $result['forum_id'],
                        'forum_name'    =>      $result['forum_name']
                    );

                    $subForums=$this->model_community_mcp->getSubForums($this->data['has_global_privilege'],$result['forum_id']);

                    foreach($subForums as $subForum){
                        $this->data['sub_forums'][$result['forum_id']][]=array(
                            'forum_id'      =>      $subForum['forum_id'],
                            'forum_name'    =>      $subForum['forum_name']
                        );
                    }
                }

                //pagination && topics awaiting approval
                $pagination = new Pagination();

                $pagination->total=$this->model_community_mcp->getDeletedPostsTotal($this->request->get);

                if (isset($this->request->get['page'])) {
                    $page = $this->request->get['page'];
                } else {
                    $page = 1;
                }

                $pagination->page = $page;
                $pagination->limit = 20;
                $start=($page-1)*$pagination->limit;

                if(isset($this->request->get['fid'])){
                    $url='mode=rde&action=dp&fid=' . $this->request->get['fid'];
                }else{
                    $url='mode=rde&action=dp';
                }

                $pagination->url = $this->url->link('community/mcp', $url . '&page={page}','SSL');

                $this->data['pagination'] = $pagination->render();

                $deletedPostResults=$this->model_community_mcp->getDeletedPosts($this->request->get,$start,$pagination->limit);

                $this->data['deleted_posts']=array();

                foreach($deletedPostResults as $deletedPostResult){
                    $this->data['deleted_posts'][]=array(
                        'post_subject'              =>      $deletedPostResult['post_subject'],
                        'posted_by'                 =>      sprintf($this->language->get('text_posted_by'),$this->url->link('community/profile','uid=' . $deletedPostResult['poster_id'] ,'SSL'),$deletedPostResult['post_username'],date($this->language->get('date_time_format_long'),$deletedPostResult['post_time'])),
                        'topic_link'                =>      $this->url->link('community/viewtopic','fid=' . $deletedPostResult['forum_id'] . '&tid=' . $deletedPostResult['topic_id'],'SSL'),
                        'topic_title'               =>      $deletedPostResult['topic_title'],
                        'fourm_link'                =>      $this->url->link('community/viewforum','fid=' . $deletedPostResult['forum_id'],'SSL'),
                        'forum_name'                =>      $deletedPostResult['forum_name'],
                        'id_str'                   =>      $deletedPostResult['post_id'] . '|' . $deletedPostResult['topic_id']
                    );
                }
                break;
        }
    }

    private function validateBwFromReport(){
        if($this->request->post['other-actions']=='w' && $this->request->post['warning-details']==''){
            $this->error['report_details']=$this->language->get('error_warning_details_empty');
        }

        if($this->request->post['other-actions']=='b' && $this->request->post['ban-reason-shown']==''){
            $this->error['report_details']=$this->language->get('error_ban_reason_shown_empty');
        }

        if($this->request->post['other-actions']=='b' && $this->request->post['ban-reason']==''){
            $this->error['report_details']=$this->language->get('error_ban_reason_empty');
        }

        if($this->request->post['other-actions']=='b' && $this->request->post['ban-length']=='u' && $this->request->post['ban-date']==''){
            $this->error['report_details']=$this->language->get('error_ban_date_empty');
        }

        $dataFormat='/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/';

        if($this->request->post['other-actions']=='b' && $this->request->post['ban-length']=='u' && !preg_match($dataFormat,$this->request->post['ban-date'])){
            $this->error['report_details']=$this->language->get('error_ban_date_format');
        }

        list(,,,,,,,$uid,,$user_type)=explode('|',$this->request->post['marked_r_id'][0]);

        if($this->request->post['other-actions']=='b' && $uid==$this->customer->getForumUserId()){
            $this->error['report_details']=$this->language->get('error_ban_self');
        }

        if($this->request->post['other-actions']=='b' && $user_type<=3){
            $this->error['report_details']=$this->language->get('error_ban_mod');
        }

        if($this->request->post['other-actions']=='w' && $uid==$this->customer->getForumUserId()){
            $this->error['report_details']=$this->language->get('error_warn_self');
        }

        if($this->request->post['other-actions']=='w' && $user_type<=3){
            $this->error['report_details']=$this->language->get('error_warn_mod');
        }

        if(!$this->error){
            return true;
        }else{
            return false;
        }
    }

    private function validateWarning(){
        if($this->request->post['warning-details']==''){
            $this->error['warning']=$this->language->get('error_warn_details_empty');
        }

        if(isset($this->request->post['warning-usernames'])){
            $validateResult=$this->model_community_mcp->validateUsers($this->request->post['warning-usernames']);

            if($validateResult=='mod'){
                $this->error['warning']=$this->language->get('error_warn_mod');
            }elseif($validateResult=='empty'){
                $this->error['warning']=$this->language->get('error_warn_user_not_exist');
            }

        if($this->request->post['warning-usernames']==''){
            $this->error['warning']=$this->language->get('error_warn_username_empty');
        }
        }

        if(!$this->error){
            return true;
        }else{
            return false;
        }
    }

    private function validateBanning(){
        if($this->request->post['ban-reason-shown']==''){
            $this->error['banning']=$this->language->get('error_ban_reason_shown_empty');
        }

        if($this->request->post['ban-reason']==''){
            $this->error['banning']=$this->language->get('error_ban_reason_empty');
        }

        if($this->request->post['ban-length']=='u' && $this->request->post['ban-date']==''){
            $this->error['banning']=$this->language->get('error_ban_date_empty');
        }

        $dataFormat='/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/';

        if($this->request->post['ban-length']=='u' && !preg_match($dataFormat,$this->request->post['ban-date'])){
            $this->error['banning']=$this->language->get('error_ban_date_format');
        }

        if($this->request->get['action']=='bu'){
            $validateResult=$this->model_community_mcp->validateUsers($this->request->post['ban-usernames']);

            if($validateResult=='mod'){
                $this->error['banning']=$this->language->get('error_ban_mod');
            }elseif($validateResult=='empty'){
                $this->error['banning']=$this->language->get('error_ban_user_not_exist');
            }
        }

        if($this->request->get['action']=='bu' && $this->request->post['ban-usernames']==''){
            $this->error['banning']=$this->language->get('error_ban_usernames_empty');
        }

        if($this->request->get['action']=='bi' && $this->request->post['ban-ips']==''){
            $this->error['banning']=$this->language->get('error_ban_ips_empty');
        }
// && !preg_match('/\d{1,3}\.d{1,3}\.d{1,3}\.d{1,3}\-\d{1,3}\.d{1,3}\.d{1,3}\.d{1,3}/',$this->request->post['ban-ips'])
        if($this->request->get['action']=='bi'){
            $ban_ip_text=nl2br($this->request->post['ban-ips']);
            $tem_ban_ips=explode('<br />',$ban_ip_text);

            $ban_ips=array();

            foreach($tem_ban_ips as $tem_ban_ip){
                $tem_ban_ip=trim(trim($tem_ban_ip),'<br />');//remove things like \n,\t

                if(!empty($tem_ban_ip)){
                    array_push($ban_ips,$tem_ban_ip);
                }
            }

            foreach($ban_ips as $ban_ip){
                if(!(preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/',$ban_ip) || preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/',$ban_ip))){
                    $this->error['banning']=$this->language->get('error_ban_ip_format');
                }
            }
        }

        if(!$this->error){
            return true;
        }else{
            return false;
        }
    }

    private function parseSpacing($str){
        $str=nl2br($str);
        $str = str_replace("\t", '&nbsp; &nbsp;', $str);
        $str = str_replace('  ', '&nbsp; ', $str);
        $str = str_replace('  ', ' &nbsp;', $str);

        return $str;
    }

    private function parseBbcode($str,$posterPermission){
        if($this->config->get('bbcode_parsing_enable')){
            if($posterPermission['posting_bbcode']){
                $pattern=array();
                $pattern[]='/\[size=(\d+)\](.*)\[\/size\]/Uis';
                $pattern[]='/\[b\](.*)\[\/b\]/Uis';
                $pattern[]='/\[i\](.*)\[\/i\]/Uis';
                $pattern[]='/\[u\](.*)\[\/u\]/Uis';
                $pattern[]='/\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*)\[\/color\]/Uis';

                if($this->config->get('bbcode_url_parsing_enable')){
                    if($posterPermission['posting_bbcode_url']){
                        $pattern[]='/\[url\](.*)\[\/url\]/Uis';
                        $pattern[]='/\[url=([^\[]+?)\](.*)\[\/url\]/Uis';
                    }
                }

                $pattern[]='/\[quote(?!&quot;.*&quot;)\](.*)\[\/quote\]/Uis';
                $pattern[]='/\[quote=&quot;(.*)&quot;\](.*)\[\/quote\]/Uis';
                $pattern[]='/\[code\](.*)\[\/code\]/Uis';

                if($this->config->get('bbcode_img_parsing_enable')){
                    if($posterPermission['posting_bbcode_img']){
                        $pattern[]='/\[img\](.*)\[\/img\]/Uis';
                    }
                }

                if($this->config->get('bbcode_flash_parsing_enable')){
                    if($posterPermission['posting_bbcode_flash']){
                        $pattern[]='/\[flash\](.*)\[\/flash\]/Uis';
                    }
                }

                $pattern[]='/\[youtube\](http:\/\/)?(www\.)?youtube.com\/watch\?v=(.*)(&amp;\w*=.*)?\[\/youtube\]/Uis';

                $replace=array();
                $replace[]='<span style="font-size:\1%;">\2</span>';
                $replace[]='<strong>\1</strong>';
                $replace[]='<em>\1</em>';
                $replace[]='<span style="text-decoration:underline;">\1</span>';
                $replace[]='<span style="color:\1;">\2</span>';

                if($this->config->get('bbcode_url_parsing_enable')){
                    if($posterPermission['posting_bbcode_url']){
                        $replace[]='<a href="\1" target="_blank">\1</a>';
                        $replace[]='<a href="\1" target="_blank">\2</a>';
                    }
                }

                $replace[]='<blockquote class="bbcode_uncited"><div>\1</div></blockquote>';
                $replace[]='<blockquote class="bbcode_uncited"><div><dl><dt>\1 Wrote:</dt><dd>\2</dd></dl></div></blockquote>';
                $replace[]='<dl class="bbcode_code"><dt>CODE: <a href="javascript:void(0)" onclick="selectCode(this); return FALSE;">SELECT ALL</a></dt><dd><code>\1</code></dd></dl>';

                if($this->config->get('bbcode_img_parsing_enable')){
                    if($posterPermission['posting_bbcode_img']){
                        $replace[]='<img src="\1" />';
                    }
                }

                if($this->config->get('bbcode_flash_parsing_enable')){
                    if($posterPermission['posting_bbcode_flash']){
                        $replace[]='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="400" width="480"><param name="quality" value="high" /><param name="movie" value="\1" /><embed height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="\1" type="application/x-shockwave-flash" width="480"></embed></object>';
                    }
                }

                $replace[]='<iframe width="560" height="315" src="http://www.youtube.com/embed/\3" frameborder="0" allowfullscreen></iframe>';

                $str=preg_replace($pattern,$replace,$str);
            }
        }

        return $str;
    }

    private function parseSmiles($str,$posterPermission){
        if($this->config->get('smiles_parsing_enable')){
            if($posterPermission['posting_smiles']){
                $smileCode=array(
                    ':D',
                    ':)',
                    ';)',
                    ':(',
                    ':o',
                    ':shock:',
                    ':?',
                    '8-)',
                    ':lol:',
                    ':x',
                    ':P',
                    ':-oops:',
                    ':cry:',
                    ':evil:',
                    ':twisted:',
                    ':roll:',
                    ':!:',
                    ':-?:',
                    ':idea:',
                    ':arrow:',
                    ':|',
                    ':mrgreen:',
                    ':geek:',
                    ':ugeek:',
                );

                $smileImage=array(
                    '<img src="catalog/view/theme/default/image/smilies/01_very_happy.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/02_smile.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/03_wink.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/04_sad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/05_surprised.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/06_shocked.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/07_confused.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/08_cool.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/09_langhing.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/10_mad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/11_razz.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/12_embarrassed.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/13_cry.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/14_evil_or_very_mad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/15_twisted_evil.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/16_rolling_eyes.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/17_exclamation.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/18_question.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/19_idea.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/20_arrow.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/21_neutral.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/22_mr._green.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/23_geek.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/24_uber_geek.gif" />'
                );

                $str=str_replace($smileCode,$smileImage,$str);
            }
        }

        return $str;
    }

    private function parseSigBbcode($str,$posterPermission){
        if($this->config->get('bbcode_parsing_enable')){
            if($posterPermission['allow_user_sig_bbcode']){
                $pattern=array();
                $pattern[]='/\[size=(\d+)\](.*)\[\/size\]/Uis';
                $pattern[]='/\[b\](.*)\[\/b\]/Uis';
                $pattern[]='/\[i\](.*)\[\/i\]/Uis';
                $pattern[]='/\[u\](.*)\[\/u\]/Uis';
                $pattern[]='/\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*)\[\/color\]/Uis';

                if($this->config->get('bbcode_url_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_url']){
                        $pattern[]='/\[url\](.*)\[\/url\]/Uis';
                        $pattern[]='/\[url=([^\[]+?)\](.*)\[\/url\]/Uis';
                    }
                }

                $pattern[]='/\[quote(?!&quot;.*&quot;)\](.*)\[\/quote\]/Uis';
                $pattern[]='/\[quote=&quot;(.*)&quot;\](.*)\[\/quote\]/Uis';
                $pattern[]='/\[code\](.*)\[\/code\]/Uis';

                if($this->config->get('bbcode_img_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_img']){
                        $pattern[]='/\[img\](.*)\[\/img\]/Uis';
                    }
                }

                if($this->config->get('bbcode_flash_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_flash']){
                        $pattern[]='/\[flash\](.*)\[\/flash\]/Uis';
                    }
                }

                $pattern[]='/\[youtube\](http:\/\/)?(www\.)?youtube.com\/watch\?v=(.*)(&amp;\w*=.*)?\[\/youtube\]/Uis';

                $replace=array();
                $replace[]='<span style="font-size:\1%;">\2</span>';
                $replace[]='<strong>\1</strong>';
                $replace[]='<em>\1</em>';
                $replace[]='<span style="text-decoration:underline;">\1</span>';
                $replace[]='<span style="color:\1;">\2</span>';

                if($this->config->get('bbcode_url_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_url']){
                        $replace[]='<a href="\1" target="_blank">\1</a>';
                        $replace[]='<a href="\1" target="_blank">\2</a>';
                    }
                }

                $replace[]='<blockquote class="bbcode_uncited"><div>\1</div></blockquote>';
                $replace[]='<blockquote class="bbcode_uncited"><div><dl><dt>\1 Wrote:</dt><dd>\2</dd></dl></div></blockquote>';
                $replace[]='<dl class="bbcode_code"><dt>CODE: <a href="javascript:void(0)" onclick="selectCode(this); return FALSE;">SELECT ALL</a></dt><dd><code>\1</code></dd></dl>';

                if($this->config->get('bbcode_img_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_img']){
                        $replace[]='<img src="\1" />';
                    }
                }

                if($this->config->get('bbcode_flash_parsing_enable')){
                    if($posterPermission['allow_user_sig_bbcode_flash']){
                        $replace[]='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="400" width="480"><param name="quality" value="high" /><param name="movie" value="\1" /><embed height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="\1" type="application/x-shockwave-flash" width="480"></embed></object>';
                    }
                }

                $replace[]='<iframe width="560" height="315" src="http://www.youtube.com/embed/\3" frameborder="0" allowfullscreen></iframe>';

                $str=preg_replace($pattern,$replace,$str);
            }
        }

        return $str;
    }

    private function parseSigSmiles($str,$posterPermission){
        if($this->config->get('smiles_parsing_enable')){
            if($posterPermission['allow_user_sig_smiles']){
                $smileCode=array(
                    ':D',
                    ':)',
                    ';)',
                    ':(',
                    ':o',
                    ':shock:',
                    ':?',
                    '8-)',
                    ':lol:',
                    ':x',
                    ':P',
                    ':-oops:',
                    ':cry:',
                    ':evil:',
                    ':twisted:',
                    ':roll:',
                    ':!:',
                    ':-?:',
                    ':idea:',
                    ':arrow:',
                    ':|',
                    ':mrgreen:',
                    ':geek:',
                    ':ugeek:',
                );

                $smileImage=array(
                    '<img src="catalog/view/theme/default/image/smilies/01_very_happy.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/02_smile.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/03_wink.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/04_sad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/05_surprised.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/06_shocked.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/07_confused.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/08_cool.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/09_langhing.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/10_mad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/11_razz.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/12_embarrassed.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/13_cry.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/14_evil_or_very_mad.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/15_twisted_evil.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/16_rolling_eyes.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/17_exclamation.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/18_question.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/19_idea.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/20_arrow.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/21_neutral.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/22_mr._green.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/23_geek.gif" />',
                    '<img src="catalog/view/theme/default/image/smilies/24_uber_geek.gif" />'
                );

                $str=str_replace($smileCode,$smileImage,$str);
            }
        }

        return $str;
    }

    private function parseURL($str,$posterPermission){
        if($this->config->get('auto_url_parsing_enable')){
            if($posterPermission['posting_bbcode_url']){
                $pattern=$replace=array();
                // matches an "xxxx://yyyy" URL at the start of a line, or after a space.xxxx can only be alpha characters. yyyy is anything up to the first space, newline, comma, double quote or <
                $pattern[]='/(^|[\n ])([\w]+?:\/\/[^ \"\n\r\t<]*)/is';
                // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing.Must contain at least 2 dots. xxxx contains either alphanum, or "-". zzzz is optional.. will contain everything up to the first space, newline,comma, double quote or <.
                $pattern[]='/(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)/is';
                // matches an email@domain type address at the start of a line, or after a space. Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
                $pattern[]='/(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)/i';

                $replace[]='\\1<a href="\\2" target="_blank">\\2</a>';
                $replace[]='\\1<a href="http://\\2" target="_blank">\\2</a>';
                $replace[]='\\1<a href="mailto:\\2@\\3">\\2@\\3</a>';

                $str=preg_replace($pattern,$replace,$str);
            }
        }

        return $str;
    }
}
?>